:root {
  --bg: #080d18;
  --bg-2: #0d1426;
  --surface: rgba(20, 28, 50, 0.72);
  --surface-solid: #141c32;
  --border: rgba(120, 145, 210, 0.18);
  --border-strong: rgba(120, 160, 255, 0.4);
  --text: #e9eefb;
  --text-dim: #98a4c6;
  --text-faint: #6b7699;
  --accent: #3d8bff;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #3d8bff, #22d3ee);
  --success: #2ee6a8;
  --danger: #ff5d7a;
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 650px at 15% -10%, rgba(61, 139, 255, 0.16), transparent 55%),
    radial-gradient(900px 600px at 100% 0%, rgba(34, 211, 238, 0.1), transparent 50%),
    linear-gradient(180deg, #080d18, #0b1120 60%, #070b14);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 13, 24, 0.82);
  backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}
.brand img {
  width: 40px; height: 40px; object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(61, 139, 255, 0.45));
}
.brand strong { font-size: 1.06rem; letter-spacing: 0.2px; }
.spacer { flex: 1; }
.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  font-size: 1.15rem;
  cursor: pointer;
  transition: all 0.16s ease;
}
.icon-btn:hover { color: #fff; border-color: var(--border-strong); transform: rotate(35deg); }

/* ------------------------------------------------------------------ layout */
.page { max-width: 1180px; margin: 0 auto; padding: 34px 22px 80px; }
.intro { text-align: center; margin-bottom: 26px; }
.intro h1 { margin: 0 0 8px; font-size: 2rem; letter-spacing: -0.6px; }
.intro p { margin: 0; color: var(--text-dim); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: stretch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 14px 40px -22px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
}
.card h2 { margin: 0 0 14px; font-size: 1rem; }

/* ------------------------------------------------------------------ upload */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  min-height: 300px;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  padding: 24px;
  background: rgba(61, 139, 255, 0.04);
  transition: all 0.2s ease;
  overflow: hidden;
}
.dropzone:hover, .dropzone.over { background: rgba(61, 139, 255, 0.12); border-color: var(--accent-2); }
.dropzone .big { font-size: 2.4rem; margin-bottom: 10px; }
.dropzone p { margin: 4px 0; color: var(--text-dim); }
.dropzone img.preview { width: 100%; max-height: 420px; object-fit: contain; border-radius: 12px; }

.generate-btn {
  margin-top: 16px;
  width: 100%;
  padding: 15px 20px;
  border: none;
  border-radius: 14px;
  background: var(--accent-grad);
  color: #041019;
  font-size: 1.02rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 14px 30px -14px rgba(61, 139, 255, 0.9);
  transition: filter 0.15s ease, opacity 0.15s ease;
}
.generate-btn:hover:not(:disabled) { filter: brightness(1.08); }
.generate-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.status-line { margin-top: 12px; font-size: 0.85rem; color: var(--text-dim); min-height: 20px; }
.progress { margin-top: 12px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent-grad); transition: width 0.3s ease; }

/* ------------------------------------------------------------------ viewer */
.viewer-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 280px;
  min-width: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #16203c, #060911);
  border: 1px solid var(--border);
}
/* Le canvas est hors flux : sa taille (plein écran ou autre) ne doit jamais
   influencer la hauteur du bloc. Il remplit simplement le conteneur. */
.viewer-wrap canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
}
/* Plein écran par CSS (position fixe) : la mise en page des blocs n'est
   jamais modifiée, ni à l'entrée ni au retour. */
.viewer-wrap.is-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  border-radius: 0;
  border: none;
}
body.no-scroll { overflow: hidden; }
.viewer-fs {
  position: absolute;
  top: 12px; right: 12px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(7, 11, 22, 0.7);
  color: var(--text-dim);
  font-size: 1.05rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: all 0.16s ease;
  z-index: 2;
}
.viewer-fs:hover { color: #fff; border-color: var(--border-strong); }
.viewer-hint {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--text-faint); text-align: center; gap: 10px;
  pointer-events: none;
}
.viewer-hint .big { font-size: 2.6rem; opacity: 0.5; }
.viewer-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ examples */
.examples { margin-top: 40px; }
.examples h2 { text-align: center; color: var(--text-dim); font-size: 0.95rem; font-weight: 500; margin-bottom: 18px; }
.example-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.example {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0a0f1e center/cover no-repeat;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.16s ease;
}
.example:hover { transform: translateY(-3px); border-color: var(--border-strong); }
.example span {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 10px;
  font-size: 0.72rem;
  background: linear-gradient(transparent, rgba(6, 10, 20, 0.9));
  color: #dfe7fb;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text); font-family: inherit; font-size: 0.86rem; font-weight: 500;
  cursor: pointer; transition: all 0.16s ease; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); background: rgba(61, 139, 255, 0.12); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent-grad); border: none; color: #041019; font-weight: 650; }
.btn.danger { border-color: rgba(255, 93, 122, 0.4); color: #ffb3c1; }
.btn.sm { padding: 7px 11px; font-size: 0.8rem; }

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 7, 14, 0.82);
  backdrop-filter: blur(6px);
  display: none;
  justify-content: flex-end;
}
.modal.open { display: flex; }
.panel {
  width: min(560px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--bg-2);
  border-left: 1px solid var(--border-strong);
  padding: 22px;
  animation: slidein 0.22s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.panel-head h2 { margin: 0; flex: 1; font-size: 1.05rem; }
.section { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px; overflow: hidden; }
.section > summary {
  cursor: pointer; padding: 12px 14px; font-size: 0.9rem; font-weight: 600;
  background: rgba(255, 255, 255, 0.03); list-style: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: "＋"; float: right; color: var(--text-faint); }
.section[open] > summary::after { content: "－"; }
.section .body { padding: 14px; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------------ forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 0.78rem; color: var(--text-dim); margin-bottom: 6px; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: rgba(6, 10, 20, 0.7); color: var(--text);
  font-family: inherit; font-size: 0.86rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61, 139, 255, 0.15); }
textarea { min-height: 200px; font-family: var(--mono); font-size: 0.78rem; line-height: 1.5; resize: vertical; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-dim); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------------ tasks/logs */
.console {
  font-family: var(--mono); font-size: 0.75rem; line-height: 1.5;
  background: #05080f; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; max-height: 240px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  color: #b9c6e6;
}
.console .line-system { color: var(--accent-2); }
.console .line-command { color: #ffb454; }
.console .line-stderr { color: #ff9db4; }
.job { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; }
.job .top { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; }
.job .top b { flex: 1; }
.status { padding: 3px 9px; border-radius: 999px; font-size: 0.7rem; border: 1px solid var(--border); }
.status.en_cours { color: var(--accent-2); border-color: rgba(34,211,238,.4); }
.status.termine { color: var(--success); border-color: rgba(46,230,168,.4); }
.status.echec, .status.annule, .status.interrompu { color: var(--danger); border-color: rgba(255,93,122,.4); }

.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; }
.result-item .thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #0a0f1e; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.12); border-top-color: var(--accent-2);
  animation: spin .9s linear infinite; margin: 26px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm); background: var(--surface-solid);
  border: 1px solid var(--border-strong); box-shadow: 0 18px 40px -18px rgba(0,0,0,.8);
  font-size: 0.85rem; max-width: 340px; animation: pop .22s ease;
}
.toast.ok { border-color: rgba(46,230,168,.5); }
.toast.err { border-color: rgba(255,93,122,.5); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

.muted { color: var(--text-faint); font-size: 0.82rem; }
.mono { font-family: var(--mono); font-size: 0.78rem; }
.hidden { display: none !important; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

.gpu-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 0.82rem; }
.gpu-row.selected { border-color: var(--accent-2); background: rgba(34,211,238,.07); }

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .intro h1 { font-size: 1.6rem; }
}
