:root {
  --ink: #1B2A20;
  --forest: #1F3A2E;
  --sage: #7A9873;
  --sage-dark: #587555;
  --paper: #FAFAF8;
  --card: #FFFFFF;
  --line: #E4E1D8;
  --muted: #6E7268;
  --ok: #3F6F52;
  --error: #A6493F;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  flex-wrap: wrap;
}
.logo { width: 42px; height: 42px; object-fit: contain; }
.brandname {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.3px;
  color: var(--forest);
}
.brandtag {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--sage-dark);
  text-transform: uppercase;
  font-weight: 600;
}
.stepper {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.step-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 5px 4px;
}
.step-pill.active { color: var(--forest); }
.step-pill.done { color: var(--ok); }
.step-dot {
  width: 19px; height: 19px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; border: 1.5px solid var(--line); color: var(--muted);
}
.step-pill.active .step-dot { background: var(--forest); color: #fff; border-color: var(--forest); }
.step-pill.done .step-dot { background: var(--ok); color: #fff; border-color: var(--ok); }
.step-arrow { color: var(--line); font-size: 12px; }
.step-pill.clickable { cursor: pointer; border-radius: 20px; }
.step-pill.clickable:hover { background: #F1F4EF; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

.foot {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 20px;
}

/* Upload zone */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 60px 24px;
  text-align: center;
  cursor: pointer;
  transition: all .15s ease;
}
.dropzone.drag { border-color: var(--sage); background: #F3F6F1; }
.dropzone h3 { margin: 12px 0 4px; font-size: 17px; font-weight: 700; }
.dropzone p { margin: 0; font-size: 13px; color: var(--muted); }
.leaf-icon { color: var(--sage-dark); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px,1fr));
  gap: 14px;
  margin-top: 22px;
}
.thumb-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.thumb-card img { width: 100%; height: 100px; object-fit: contain; margin-bottom: 6px; }
.thumb-num { font-size: 10.5px; color: var(--muted); font-family: monospace; }
.thumb-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb-x {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px;
  border-radius: 50%; border: 1px solid var(--line); background: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted);
}

.actions-row { display: flex; justify-content: flex-end; margin-top: 24px; }
.actions-row.split { justify-content: space-between; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 9px; padding: 11px 18px; font-size: 13px; font-weight: 700;
  border: none; cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--forest); color: #fff; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-small {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-small.danger { color: var(--error); }

/* Generate step */
.gen-panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.gen-title { font-size: 14px; font-weight: 700; margin-bottom: 16px; }
.gen-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.gen-num { width: 90px; font-size: 12px; font-family: monospace; color: var(--muted); }
.gen-name { flex: 1; font-size: 13px; font-weight: 600; min-width: 120px; }
.gen-badge {
  font-size: 10.5px; padding: 3px 9px; border-radius: 20px; display: flex; align-items: center; gap: 4px;
  background: #F1F1EC; color: var(--muted);
}
.gen-badge.pending { background: #FBF3E2; color: #8A6A22; }
.gen-badge.done { background: #EAF2ED; color: var(--ok); }
.gen-badge.failed { background: #F7EAE8; color: var(--error); cursor: help; }
.gen-count { font-family: monospace; font-weight: 600; color: var(--muted); font-size: 12px; }
.gen-sub { font-size: 12px; color: var(--muted); margin: -10px 0 16px; }

/* Review / cards */
.style-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 16px;
}
.style-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px; flex-wrap: wrap; gap: 10px;
}
.style-id { flex: 1; min-width: 200px; }
.style-num { font-size: 11px; font-family: monospace; color: var(--muted); letter-spacing: .5px; }
.style-name-input {
  font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 700; color: var(--forest);
  border: 1px solid transparent; outline: none; background: transparent;
  margin: 2px 0 0 -6px; padding: 3px 6px; border-radius: 6px;
  width: 100%; max-width: 460px; text-overflow: ellipsis;
}
.style-name-input:hover { border-color: var(--line); }
.style-name-input:focus { border-color: var(--sage); background: #fff; }
.card-btns { display: flex; gap: 6px; }

.img-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.img-grid img { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #f3f3f0; display: block; }
.img-wrap { position: relative; }
.img-kind {
  position: absolute; left: 8px; bottom: 8px; font-size: 10px; font-weight: 600;
  letter-spacing: .4px; text-transform: uppercase; color: #fff;
  background: rgba(27,42,32,.62); padding: 3px 7px; border-radius: 20px;
  backdrop-filter: blur(2px); pointer-events: none;
}
.img-dl {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px;
  border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.92);
  color: var(--forest); display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity .12s ease; padding: 0;
}
.img-wrap:hover .img-dl, .img-dl:focus-visible { opacity: 1; }
.img-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 6px; }
.img-actions .btn-small { justify-content: center; }
.img-actions .btn-small:disabled { opacity: .4; cursor: not-allowed; }
.btn-small:disabled { opacity: .4; cursor: not-allowed; }

/* Failed / in-flight generation, sized to match the image it stands in for */
.img-error, .img-busy {
  aspect-ratio: 1; width: 100%; border-radius: 8px; border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 14px; text-align: center; font-size: 11px; line-height: 1.45;
}
.img-error { background: #FCF6F5; border-color: #E8D5D1; color: var(--error); }
.img-error span { max-height: 7.5em; overflow: hidden; }
.img-busy { background: #f3f3f0; color: var(--muted); }
.img-busy svg { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Details step */
.detail-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px;
  margin-bottom: 12px; display: grid; grid-template-columns: 184px 1fr; gap: 18px;
}
.detail-visual { display: flex; flex-direction: column; gap: 8px; }
.detail-hero {
  width: 184px; height: 184px; object-fit: contain; border-radius: 8px;
  border: 1px solid var(--line); background: #f7f7f4;
}

/* Hero picker — click a thumbnail to choose which visual leads the slide */
.hero-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.hero-thumb {
  position: relative; padding: 0; border-radius: 7px; overflow: hidden; cursor: pointer;
  border: 2px solid var(--line); background: #f7f7f4; flex: none;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px;
}
.hero-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.hero-thumb:hover:not(:disabled) { border-color: var(--sage); }
.hero-thumb.active { border-color: var(--forest); box-shadow: 0 0 0 2px rgba(31,58,46,.16); }
.hero-thumb:disabled { opacity: .5; cursor: not-allowed; }
.hero-thumb.no-image { font-size: 14px; }
.hero-thumb-label {
  position: absolute; inset: auto 0 0 0; font-size: 8px; font-weight: 700; letter-spacing: .3px;
  text-transform: uppercase; color: #fff; background: rgba(27,42,32,.6); padding: 2px 0; text-align: center;
}
.hero-thumb.active .hero-thumb-label { background: var(--forest); }
.detail-head { font-size: 11px; font-family: monospace; color: var(--muted); margin-bottom: 4px; }
.field-row { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-top: 6px; }
.field label {
  display: block; font-size: 10px; font-weight: 700; color: var(--muted);
  letter-spacing: .6px; margin-bottom: 3px; text-transform: uppercase;
}
.field input {
  width: 100%; font-size: 13px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 7px; outline: none; font-family: inherit; box-sizing: border-box;
}
.field input:focus { border-color: var(--sage); }

/* Export preview */
.export-note {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 20px;
}
.export-note-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.export-note h3 { margin: 0 0 4px; font-size: 15px; font-family: 'Playfair Display', serif; color: var(--forest); }
.export-note p { margin: 0; font-size: 13px; color: var(--muted); max-width: 620px; }
.deck-title-field { min-width: 240px; }
.export-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.export-actions .btn { min-width: 190px; justify-content: center; }
.export-actions .btn:disabled { opacity: .45; cursor: not-allowed; }
.export-actions svg { flex: none; }
.warn {
  margin-top: 14px; font-size: 12px; color: #8A6A22; background: #FBF3E2;
  border: 1px solid #EFDFBB; border-radius: 8px; padding: 9px 12px;
}
.export-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 14px;
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px;
}
.export-card img.hero {
  width: 100%; max-height: 560px; object-fit: contain;
  border-radius: 8px; border: 1px solid var(--line); background: #f7f7f4;
}
.export-name {
  font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 700;
  color: var(--forest); margin: 2px 0 12px;
}
.export-body { font-size: 13px; margin-bottom: 10px; overflow-wrap: anywhere; }
.export-rate { font-size: 20px; font-weight: 700; color: var(--sage-dark); margin-bottom: 10px; }
.mini-label {
  display: block; font-size: 10px; font-weight: 700; color: var(--muted);
  letter-spacing: .6px; margin-bottom: 3px;
}

.hint { font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.hint-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; margin-bottom: 16px; flex-wrap: wrap;
}
.hint-row .hint { margin: 0; flex: 1; min-width: 220px; }
.empty {
  background: var(--card); border: 1px dashed var(--line); border-radius: 14px;
  padding: 40px; text-align: center; font-size: 13px; color: var(--muted);
}

/* Progress bar on the Generate step */
.progress { height: 5px; background: #EDEDE7; border-radius: 20px; overflow: hidden; margin-bottom: 18px; }
.progress-bar { height: 100%; background: var(--sage-dark); border-radius: 20px; transition: width .3s ease; }

/* Any loader icon spins, wherever it appears */
.spin { animation: spin 1.1s linear infinite; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--forest); color: #fff; font-size: 13px; font-weight: 600;
  padding: 11px 18px; border-radius: 10px; box-shadow: 0 8px 26px rgba(27,42,32,.22);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
  max-width: min(560px, calc(100vw - 32px)); text-align: center; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--error); }

@media (max-width: 760px) {
  .app { padding: 20px 16px 48px; }
  .img-grid { grid-template-columns: 1fr; gap: 12px; }
  .detail-card, .export-card { grid-template-columns: 1fr; }
  .detail-hero { width: 100%; height: 220px; }
  .field-row { grid-template-columns: 1fr; }
  .export-actions .btn { min-width: 0; flex: 1 1 100%; }
  .stepper { width: 100%; margin-left: 0; }
  .style-name-input { max-width: 100%; }
}
