/* Animal Loaf Generator — tool-only CSS.
   Owns the DS "AI toolkit" subset: .panel*, .upload*, .progress*, .step, .result*, .credit (+ .alg* helpers).
   Primitives (.btn*, .pill*, .badge*, .select-wrap, .field*, .thumb*) come from the theme and are NOT redefined here.
   Tokens (--color-*, --space-*, --radius-*, --shadow-*, --font-*, --text-*, --duration-*, --ease-*, --gradient-brand,
   --leading-*, --tracking-*, --weight-*) are defined by the theme. Minimum font size: 12px. */

/* Safety: our own display rules must never beat the hidden attribute
   (the engine-controlled data-gf-if-* blocks live inside this root). */
.alg [hidden] { display: none !important; }

.alg { display: block; }

/* ---------- Guest gate ---------- */
.alg-gate {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-4);
  padding: var(--space-8) var(--space-6); text-align: center;
  border-radius: var(--radius-2xl); border: 1px solid var(--color-border-default); background: var(--color-bg-subtle);
}
.alg-gate__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.alg-gate__note { font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---------- Paused notice ---------- */
.alg-paused {
  margin-bottom: var(--space-4); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); background: var(--color-warning-soft); color: var(--color-warning);
}
.alg-paused p { margin: 0; font-size: var(--text-sm); line-height: var(--leading-normal); }

/* ---------- Generator panel ---------- */
.alg .panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-6); align-items: stretch; }
.alg .panel__side {
  display: flex; flex-direction: column; gap: var(--space-5); min-width: 0;
  padding: var(--space-6); border-radius: var(--radius-2xl);
  border: 1px solid var(--color-border-default); background: var(--color-bg-subtle);
}
.alg .panel__side--output { background: var(--color-bg-card); box-shadow: var(--shadow-card); }
.alg .panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.alg .panel__title {
  font-family: var(--font-ui); font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--color-text-muted);
}
.alg .panel__foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  margin-top: auto; padding-top: var(--space-2);
}
.alg .panel__foot [data-gen] { flex: 1 1 auto; min-width: 0; }

.alg .credit {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; white-space: nowrap;
  border-radius: var(--radius-full); border: 1px solid var(--color-border-default);
  font-family: var(--font-ui); font-size: 12px; color: var(--color-text-secondary);
}
.alg .credit i { width: 8px; height: 8px; border-radius: 50%; background: var(--color-brand-secondary); box-shadow: 0 0 8px var(--color-brand-secondary); }
.alg .credit [data-gf-credits] { color: var(--color-text-primary); font-weight: var(--weight-semibold); }

/* ---------- Upload area ---------- */
.alg .upload {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 200px; padding: var(--space-8) var(--space-6); text-align: center;
  border-radius: var(--radius-lg); border: 1.5px dashed var(--color-border-strong); background: var(--color-bg-page);
  cursor: pointer; transition: border-color var(--duration-base), background-color var(--duration-base);
}
.alg .upload:hover { border-color: var(--color-text-secondary); background: var(--color-bg-card); }
.alg .upload:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 3px; }
.alg .upload.is-drag { border-color: var(--color-brand-primary); background: var(--color-brand-primary-soft); }
.alg .upload.is-drag .upload__icon { transform: translateY(-4px) scale(1.05); background: var(--color-brand-primary); color: #111; }
.alg .upload__idle { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.alg .upload__icon {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-content: center;
  background: var(--color-bg-surface); color: var(--color-text-primary); margin-bottom: var(--space-2);
  transition: transform var(--duration-base) var(--ease-spring), background-color var(--duration-base), color var(--duration-base);
}
.alg .upload__icon svg { width: 22px; height: 22px; }
.alg .upload__title { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.alg .upload__title u { text-decoration-color: var(--color-brand-primary); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.alg .upload__hint { margin: 0; font-size: var(--text-xs); color: var(--color-text-muted); }
.alg .upload__file {
  display: none; align-items: center; gap: var(--space-3); width: 100%; min-width: 0;
  padding: var(--space-3) var(--space-4); text-align: left;
  border-radius: var(--radius-md); border: 1px solid var(--color-border-default); background: var(--color-bg-card);
}
.alg .upload.has-file { align-items: stretch; border-style: solid; }
.alg .upload.has-file .upload__file { display: flex; }
.alg .upload.has-file .upload__idle { display: none; }
.alg .upload__thumb { width: 56px; height: 56px; flex: none; border-radius: var(--radius-sm); overflow: hidden; background: var(--thumbnail-b); }
.alg .upload__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.alg .upload__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alg .upload__file-name { font-size: var(--text-sm); font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alg .upload__file-size { font-family: var(--font-ui); font-size: 12px; color: var(--color-text-muted); }
.alg .upload__file button {
  margin-left: auto; flex: none; height: 28px; padding: 0 10px; cursor: pointer;
  border-radius: var(--radius-full); border: 1px solid var(--color-border-default); background: transparent;
  font-family: var(--font-ui); font-size: 12px; color: var(--color-text-muted);
  transition: background-color var(--duration-base), color var(--duration-base), border-color var(--duration-base);
}
.alg .upload__file button:hover { background: var(--color-bg-surface); color: var(--color-error); border-color: var(--color-error); }
.alg .upload__file button:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 2px; }

/* ---------- Style pills + scene select ---------- */
.alg .alg-field { gap: var(--space-2); }
.alg .pill-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ---------- Status / error line ---------- */
.alg .alg-msg { margin: 0; font-size: var(--text-sm); line-height: var(--leading-relaxed); color: var(--color-text-secondary); }
.alg .alg-msg:not(:empty) { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--color-border-default); background: var(--color-bg-card); }
.alg .alg-msg:empty { display: none; }
.alg .alg-msg a { color: var(--color-text-link); font-weight: var(--weight-semibold); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Generation progress ---------- */
.alg .progress { display: flex; flex-direction: column; gap: var(--space-3); }
.alg .progress__bar { height: 6px; border-radius: 999px; background: var(--color-bg-surface); overflow: hidden; }
.alg .progress__bar i { display: block; height: 100%; width: 0; background: var(--gradient-brand); border-radius: inherit; transition: width .6s var(--ease-out); }
.alg .progress__steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.alg .step {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  font-family: var(--font-ui); font-size: 12px; color: var(--color-text-muted);
  transition: color var(--duration-base);
}
.alg .step::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; flex: none;
  transition: background-color var(--duration-base), border-color var(--duration-base), box-shadow var(--duration-base);
}
.alg .step.is-active { color: var(--color-brand-primary); }
.alg .step.is-active::before { background: var(--color-brand-primary); border-color: var(--color-brand-primary); box-shadow: 0 0 10px var(--color-brand-primary); }
.alg .step.is-done { color: var(--color-text-secondary); }
.alg .step.is-done::before { background: var(--color-success); border-color: var(--color-success); }
.alg .progress__label {
  display: flex; justify-content: space-between; gap: var(--space-3);
  font-family: var(--font-ui); font-size: var(--text-xs); color: var(--color-text-secondary);
}
.alg .progress__label b { color: var(--color-text-primary); font-weight: var(--weight-medium); }

/* ---------- Empty state ---------- */
.alg .alg-empty { display: grid; place-items: center; align-content: center; gap: var(--space-4); flex: 1; padding: var(--space-6); min-height: 200px; }
.alg .alg-empty__frame { position: relative; width: min(260px, 100%); aspect-ratio: 1 / 1; border-radius: var(--radius-lg); overflow: hidden; background: var(--thumbnail-b); box-shadow: var(--shadow-card); }
.alg .alg-empty__thumb { width: 100%; height: 100%; border-radius: 0; }
.alg .alg-empty__sample { display: block; width: 100%; height: 100%; object-fit: cover; }
.alg .alg-empty__badge { position: absolute; left: 10px; top: 10px; background: rgba(6,6,6,.72); color: #ffffff; backdrop-filter: blur(6px); }
.alg .alg-empty__text { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); text-align: center; max-width: 360px; }

/* ---------- Result ---------- */
.alg .result {
  display: grid; grid-template-columns: minmax(0, 280px) minmax(0, 1fr); gap: var(--space-6);
  padding: var(--space-4); border-radius: var(--radius-2xl);
  border: 1px solid var(--color-border-default); background: var(--color-bg-elevated); box-shadow: var(--shadow-card);
}
.alg .result:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 3px; }
.alg .result__thumb {
  position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius-lg); overflow: hidden;
  background: var(--thumbnail-b); box-shadow: var(--shadow-card);
}
.alg .result__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.alg .result__body { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.alg .result__title { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.alg .result__meta { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.alg .result__text { margin: 0; font-size: var(--text-sm); color: var(--color-text-secondary); line-height: var(--leading-relaxed); }
.alg .result__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .alg .panel { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .alg .panel__side { padding: var(--space-4); }
  .alg .upload { min-height: 140px; padding: var(--space-4); }
  .alg .panel__foot { flex-direction: column; align-items: stretch; }
  .alg .credit { align-self: flex-start; }
  .alg .result { grid-template-columns: 1fr; }
  .alg .result__thumb { width: 100%; max-width: 320px; margin: 0 auto; }
  .alg .progress__steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-1) var(--space-2); }
}
@media (prefers-reduced-motion: reduce) {
  .alg .progress__bar i, .alg .upload__icon, .alg .step::before, .alg .upload { transition: none; }
}
