* {
  box-sizing: border-box;
}

/* For Impact OS suite brand: black background, yellow + white text, Kanit.
   Yellow (#FFDB2A) and the gray scale come from the shared suite sidebar. */
:root {
  --bg: #0a0a0a;
  --card: #1a1a1a;
  --ink: #ffffff;
  --muted: #a1a1aa;
  --accent: #ffdb2a;
  --accent-dark: #e6c51f;
  --accent-tint: rgba(255, 219, 42, 0.1);
  --accent-line: rgba(255, 219, 42, 0.35);
  --border: #2a2a2a;
  --field: #111111;
  --error: #ff6b6b;
  --ok: #4ade80;
  --radius: 10px;
}

body {
  margin: 0;
  font-family:
    "Kanit",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

#app {
  max-width: 960px;
  margin: 32px auto 64px;
  padding: 0 16px;
}

.hidden {
  display: none !important;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 16px;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 10px;
}
h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
}
p {
  line-height: 1.5;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.error {
  color: var(--error);
  font-weight: 600;
}
.notice {
  background: var(--accent-tint);
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 0.92rem;
}

input[type="password"],
input[type="email"],
input[type="url"],
input[type="text"],
textarea {
  width: 100%;
  padding: 11px 13px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 6px 0 14px;
  font-family: inherit;
  background: var(--field);
  color: var(--ink);
}
input::placeholder,
textarea::placeholder {
  color: #71717a;
}

input[type="file"] {
  margin: 6px 0 10px;
  display: block;
  color: var(--muted);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-top: 14px;
}

/* Radio / checkbox rows (quality tiers, format picker) */
.radio-row {
  display: block;
  margin: 8px 0;
  font-size: 0.95rem;
  cursor: pointer;
}
.radio-row input {
  margin-right: 6px;
  accent-color: var(--accent);
}

button {
  font-family: inherit;
  font-size: 0.98rem;
  border-radius: 8px;
  cursor: pointer;
  padding: 11px 20px;
  border: 1px solid transparent;
}

/* Primary actions are yellow — black text for contrast on the brand yellow. */
button.primary,
.button-link.primary {
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 600;
}
button.primary:hover,
.button-link.primary:hover {
  background: var(--accent-dark);
}
button.primary:disabled {
  opacity: 0.55;
  cursor: default;
}
button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}
button.secondary:hover {
  border-color: var(--accent);
}
button.secondary:disabled {
  opacity: 0.55;
  cursor: default;
}
button.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 8px;
}
button.link-btn:hover {
  color: var(--accent);
}

.button-link {
  display: inline-block;
  border-radius: 8px;
  padding: 11px 20px;
  text-decoration: none;
  font-size: 0.98rem;
  text-align: center;
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}
.nav-row .primary:only-child {
  margin-left: auto;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.choice {
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}
.choice:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(255, 219, 42, 0.15);
}
.choice.selected {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.choice-title {
  font-weight: 700;
  color: var(--accent);
}
.choice-sub {
  color: var(--muted);
  font-size: 0.88rem;
}

/* Template thumbnail grid (multi-select) */
.template-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.template-toolbar-links {
  white-space: nowrap;
}
.template-toolbar-links .link-btn {
  padding: 4px 6px;
  font-size: 0.88rem;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.template-card {
  position: relative;
  background: var(--field);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}
.template-card .tick {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(10, 10, 10, 0.85);
  color: var(--muted);
  font-weight: 700;
  line-height: 26px;
  text-align: center;
  font-size: 15px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.template-card.selected {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.template-card.selected .tick {
  background: var(--accent);
  color: #0a0a0a;
}
.template-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(255, 219, 42, 0.15);
}
.template-card img {
  width: 100%;
  border-radius: 6px;
  display: block;
  background: var(--bg);
}
.template-card .template-label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-top: 8px;
}

/* Harvested landing-page image grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.image-pick {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: var(--field);
  aspect-ratio: 1;
}
.image-pick img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-pick.selected {
  border-color: var(--accent);
}
.image-pick .tick {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(10, 10, 10, 0.85);
  color: var(--muted);
  font-weight: 700;
  line-height: 24px;
  text-align: center;
  font-size: 14px;
}
.image-pick.selected .tick {
  background: var(--accent);
  color: #0a0a0a;
}

/* Progress list, grouped by template */
.progress-group {
  margin-top: 22px;
}
.progress-group h2 {
  margin: 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
  color: var(--accent);
}
.progress-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.progress-list li {
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.progress-list li:last-child {
  border-bottom: none;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-name {
  font-weight: 600;
}
.progress-status {
  width: 24px;
  text-align: center;
  font-weight: 700;
}
.progress-status.done {
  color: var(--ok);
}
.progress-status.failed {
  color: var(--error);
}
.progress-retry {
  margin-left: auto;
  padding: 6px 14px;
  font-size: 0.85rem;
}
.progress-error {
  margin: 6px 0 0 34px;
}
.spinner-mini {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Clone text-mapping step: one row per text element on the reference ad */
.textmap-row {
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--border);
}
.textmap-row:last-child {
  border-bottom: none;
}
.textmap-original {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}
.textmap-role {
  display: inline-block;
  background: var(--accent-tint);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 8px;
  vertical-align: 1px;
}
.textmap-chars {
  white-space: nowrap;
}
.textmap-row input {
  margin: 4px 0 2px;
}
.textmap-select,
select.textmap-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 4px 0 2px;
  font-family: inherit;
  background: var(--field);
  color: var(--ink);
}
.textmap-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.textmap-short {
  margin: 2px 0 0;
}
.textmap-manual-toggle {
  margin-left: auto;
  padding: 0 4px;
  font-size: 0.8rem;
}
.textmap-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 22px;
}
.textmap-counter {
  font-size: 0.8rem;
  color: var(--muted);
}
.textmap-counter.amber {
  color: #fbbf24;
  font-weight: 600;
}
.textmap-counter.red {
  color: var(--error);
  font-weight: 600;
}
.textmap-fit {
  padding: 0 4px;
  font-size: 0.8rem;
}
.textmap-fit:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Clone step: preview of the uploaded reference ad */
.clone-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}
.clone-preview img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-shrink: 0;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
/* History rows: cloned-ad runs show a mini thumbnail of the ad they copied */
.history-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.history-thumb {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.history-list li:last-child {
  border-bottom: none;
}
.history-open {
  white-space: nowrap;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.result-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Results: one group of banner cards per template */
.result-group-title {
  margin: 24px 4px 12px;
  font-size: 1.15rem;
  color: var(--accent);
}
.result-group:first-child .result-group-title {
  margin-top: 8px;
}
.banner-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
@media (max-width: 760px) {
  .banner-row {
    grid-template-columns: 1fr;
  }
}
.banner-frame {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Previews must NEVER crop — the downloaded file is the truth, and a preview
   that hides edges reads as a broken banner (real founder complaint). Every
   variant letterboxes (contain), nothing overflows. */
.banner-frame img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
}
.banner-frame.feed img,
.banner-frame.story img {
  max-height: 560px;
  width: auto;
}
.banner-frame.landscape img {
  width: 100%;
}
.banner-actions {
  margin-top: 12px;
}

/* Which source photo a banner card was made from */
.source-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -4px 0 10px;
}
.source-chip img {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* Multiply flow: avatar entry blocks */
.avatar-block {
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--border);
}
.avatar-block:last-child {
  border-bottom: none;
}
.avatar-block textarea {
  width: 100%;
  padding: 11px 13px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 6px 0 4px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  background: var(--field);
  color: var(--ink);
}
.avatar-block textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.avatar-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar-head .link-btn {
  margin-left: auto;
  padding: 0 4px;
  font-size: 0.8rem;
}

/* Multiply flow: per-avatar group headers on the headlines step */
.multiply-group {
  margin-top: 20px;
}
.multiply-group h2 {
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
  color: var(--accent);
}

/* Multiply flow: proof banner side-by-side with the original */
.proof-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}
@media (max-width: 640px) {
  .proof-compare {
    grid-template-columns: 1fr;
  }
}
.proof-compare figure {
  margin: 0;
}
.proof-compare figcaption {
  margin-top: 6px;
  text-align: center;
}
.proof-compare .banner-frame img {
  max-height: 420px;
  width: auto;
}

.tweak-controls {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.tweak-controls input {
  flex: 1;
  margin: 6px 0 0;
}
.tweak-controls button {
  margin-top: 6px;
  white-space: nowrap;
}

/* --- Ad Lab additions: topbar chips, auth tabs, account, paywall --- */

a.brand-name {
  text-decoration: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.balance-chip {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-tint);
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
}

.balance-chip.low {
  color: var(--error);
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.4);
}

.balance-chip:hover {
  border-color: var(--accent);
}

a.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

a.link-btn:hover {
  color: var(--ink);
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.auth-tab {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--muted);
  cursor: pointer;
}

.auth-tab.selected {
  color: #000;
  background: var(--accent);
  border-color: var(--accent);
}

#view-auth form input,
#view-reset form input {
  width: 100%;
  margin-bottom: 4px;
}

#view-auth form button.primary,
#view-reset form button.primary {
  margin-top: 12px;
}

.topup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0;
}

.ledger-plus {
  color: var(--ok);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ledger-minus {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#view-account h2 {
  font-size: 18px;
  margin: 28px 0 8px;
}

#view-auth a,
#view-account a {
  color: var(--accent);
}

/* --- Drop zones: big, friendly file targets (click or drag & drop) --- */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--field);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    transform 0.1s;
  margin: 8px 0 4px;
}

.dropzone:hover {
  border-color: var(--accent-line);
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-tint);
  transform: scale(1.005);
}

.dropzone-icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  color: var(--accent);
}

.dropzone-icon svg {
  width: 100%;
  height: 100%;
}

.dropzone-title {
  font-weight: 600;
  font-size: 16px;
}

.dropzone-title span {
  color: var(--accent);
}

.dropzone-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
  font-weight: 300;
}

.dropzone.has-file {
  border-style: solid;
  border-color: var(--accent-line);
  padding: 20px 24px;
}

/* The uploaded-image preview sits inside the flow below the zone */
.clone-preview {
  margin-top: 14px;
}
