/* Marketplace Listing Generator — mobile-first, dark by default. */

:root {
  --bg: #0b0f14;
  --surface: #131a23;
  --surface-2: #1a2430;
  --border: #26323f;
  --text: #e8edf3;
  --muted: #94a3b4;
  --accent: #4f9cf9;
  --accent-ink: #061321;
  --ok: #3fb984;
  --warn: #e3a949;
  --error: #f0736a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --maxw: 780px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --border: #d8e0ea;
    --text: #16202b;
    --muted: #5d6b7c;
    --accent: #1668d6;
    --accent-ink: #ffffff;
    --shadow: 0 6px 20px rgba(19, 38, 62, 0.09);
  }
}

* { box-sizing: border-box; }

/* Class-level `display` beats the `hidden` attribute's user-agent rule, which
   would otherwise leave hidden overlays and grids on the page swallowing taps.
   Every panel in this app is toggled via `hidden`, so make it authoritative. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 1.32rem; margin: 0 0 .25rem; letter-spacing: -0.01em; }
h2 { font-size: .95rem; margin: 0 0 .5rem; letter-spacing: .01em; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ── Layout ───────────────────────────────────────────────────── */

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}
.wrap.narrow { max-width: 420px; padding-top: 3rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
}

.stack { display: flex; flex-direction: column; gap: .85rem; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; margin-top: .35rem; }
.row-between { justify-content: space-between; align-items: flex-start; }
/* Sits the runs counter on the same line as the button it applies to. */
.row-baseline { align-items: center; margin-top: .35rem; }

/* "Hello Robert", above the steps. Present but quiet — it greets, it does not
   compete with the heading of whatever step they are on. */
.greeting { font-size: 1.05rem; font-weight: 650; margin: 0 0 .6rem; }

/* The day's remaining runs, counting down beside the Analyse button. */
#quota-note { margin: 0; }
#quota-note.quota-low { color: var(--warn); }
.quota-figure { margin: 0; font-size: 1.15rem; font-weight: 600; }

/* ── Top bar ──────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
/* A flex item will not shrink below its content unless min-width is cleared.
   Without this the long product name pushes the buttons off a phone screen
   and the whole page scrolls sideways. */
.brand { display: flex; align-items: center; gap: .55rem; min-width: 0; font-weight: 650; font-size: .95rem; }
.brand-name,
.brand-name-short { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Exactly one of the two is ever displayed, so screen readers read one name. */
.brand-name-short { display: none; }
/* An original storefront mark. It reads as "marketplace" without borrowing
   anyone's trademark, and works at 20px in the bar and 56px on sign-in. */
.brand-mark {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
}
.mark-glyph {
  width: 70%; height: 70%;
  fill: none; stroke: #fff; stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round;
}

.signin-card { text-align: center; }
.signin-card .field, .signin-card .row { text-align: left; }
.signin-card .row { justify-content: center; }
.invite-tool {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .8rem; background: var(--surface-2);
}
.invite-tool summary { cursor: pointer; font-weight: 600; font-size: .88rem; }
.invite-tool > *:not(summary) { margin-top: .6rem; }
.invite-tool input[readonly] { font-size: .82rem; color: var(--muted); }

.signin-mark {
  width: 56px; height: 56px; border-radius: 16px;
  display: inline-grid; place-items: center; margin-bottom: .75rem;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: var(--shadow);
}
/* The controls never shrink; the title gives way instead. */
.topbar-actions { display: flex; align-items: center; gap: .35rem; flex: 0 0 auto; }
.chip {
  font-size: .78rem; color: var(--muted);
  max-width: 11ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* On a phone the title and the signed-in address are the least useful things
   up here, so they go rather than Settings and Sign out. The address moves
   into the Settings panel, where there is room for it. */
@media (max-width: 520px) {
  .brand-name, .chip { display: none; }
  .brand-name-short { display: inline; }
  .topbar-inner { padding-left: .75rem; padding-right: .75rem; }
}

/* ── Steps ────────────────────────────────────────────────────── */

.steps {
  display: flex; gap: .4rem; list-style: none;
  margin: 0 0 1rem; padding: 0; font-size: .82rem;
}
.steps li {
  flex: 1; display: flex; align-items: center; gap: .4rem;
  color: var(--muted); padding: .45rem .5rem;
  border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--border); white-space: nowrap; overflow: hidden;
}
.steps li span {
  width: 20px; height: 20px; flex: none;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); font-size: .74rem; font-weight: 700;
}
.steps li.active { color: var(--text); border-color: var(--accent); }
.steps li.active span { background: var(--accent); color: var(--accent-ink); }
.steps li.done span { background: var(--ok); color: #04150e; }

/* ── Controls ─────────────────────────────────────────────────── */

.btn {
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: .62rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer; transition: filter .15s, opacity .15s;
  min-height: 42px;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: .38rem .7rem; font-size: .84rem; min-height: 34px; }
/* An <a> styled as a button, so "get a key" reads as tappable rather than as
   a stray underlined phrase in body text. */
.btn-link {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; color: var(--text);
}

.field { display: flex; flex-direction: column; gap: .32rem; font-size: .88rem; }
.field > span { font-weight: 600; }
.field em { font-style: normal; font-weight: 400; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], textarea, select {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .6rem .7rem; width: 100%;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible,
.btn:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Profile form groups. */
.group {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .85rem .9rem; margin: 0 0 .2rem;
  display: flex; flex-direction: column; gap: .7rem;
  min-width: 0;
}
.group legend {
  padding: 0 .4rem; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

.check { display: flex; align-items: flex-start; gap: .55rem; font-size: .88rem; }
.check input { margin-top: .25rem; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }

.choices { display: flex; flex-wrap: wrap; gap: .4rem; }
.choice {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: .4rem .8rem; font-size: .86rem; cursor: pointer;
}
.choice.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
/* "Unknown" and "Other" sit slightly back from the real answers, so the
   model's suggestions still read as the primary choices. */
.choice-alt { background: transparent; color: var(--muted); border-style: dashed; }
.choice-alt.selected { border-style: solid; }
.other-input { margin-top: .5rem; }

/* ── Dropzone and thumbnails ──────────────────────────────────── */

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 1.6rem 1rem; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  background: var(--surface-2); transition: border-color .15s, background .15s;
  margin-bottom: .85rem;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); }
.dropzone-icon {
  width: 34px; height: 26px; border-radius: 5px; margin-bottom: .3rem;
  border: 2px solid var(--muted); position: relative;
}
.dropzone-icon::after {
  content: ""; position: absolute; inset: auto 4px 3px 4px; height: 9px;
  border-radius: 3px 3px 0 0;
  background: var(--muted); clip-path: polygon(0 100%, 32% 22%, 58% 100%, 74% 55%, 100% 100%);
}

.thumbs {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: .5rem; margin-bottom: .85rem;
}
.thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-remove {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .68); color: #fff; font-size: 15px; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
}
.thumb-badge {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(0, 0, 0, .68); color: #fff;
  font-size: .64rem; padding: .1rem .35rem; border-radius: 4px; letter-spacing: .03em;
}

/* ── Callouts and alerts ──────────────────────────────────────── */

.callout {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .8rem .9rem; margin-bottom: .85rem;
}
.callout-accent { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.callout-warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }
.callout ul { margin: 0; padding-left: 1.1rem; }
.callout li { margin-bottom: .3rem; font-size: .89rem; }
.callout li:last-child { margin-bottom: 0; }
.callout li .why { color: var(--muted); font-size: .82rem; display: block; }

.alert {
  border-radius: var(--radius-sm); padding: .6rem .8rem; font-size: .87rem;
  border: 1px solid var(--border); background: var(--surface-2); margin-bottom: .8rem;
}
.alert ul, .alert li { margin: 0; }
.alert-info { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.alert-ok { border-color: color-mix(in srgb, var(--ok) 50%, var(--border)); }
.alert-warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); padding-left: 1.6rem; }
.alert-error { border-color: color-mix(in srgb, var(--error) 55%, var(--border)); color: var(--error); }

/* ── Question blocks ──────────────────────────────────────────── */

.question {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .8rem .9rem; background: var(--surface-2);
}
.question .q { font-weight: 600; font-size: .92rem; margin-bottom: .15rem; }
.question .why { color: var(--muted); font-size: .81rem; margin-bottom: .55rem; }

/* ── Listing output ───────────────────────────────────────────── */

.out-field {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: .7rem; overflow: hidden; background: var(--surface-2);
}
.out-head {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .45rem .7rem; background: color-mix(in srgb, var(--bg) 55%, var(--surface-2));
  border-bottom: 1px solid var(--border);
}
.out-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
.out-body { padding: .7rem; white-space: pre-wrap; word-break: break-word; font-size: .93rem; }
.out-body.big { font-size: 1.06rem; font-weight: 600; line-height: 1.35; }
.out-hint { font-size: .8rem; color: var(--muted); padding: 0 .7rem .6rem; }

.alt-title {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .45rem .7rem; border-top: 1px dashed var(--border); font-size: .88rem;
}

.pricing-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: .5rem; padding: .7rem;
}
.price-cell { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .55rem .6rem; }
.price-cell .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.price-cell .v { font-size: 1.08rem; font-weight: 700; }

.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; padding: .7rem; }
.tag { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: .22rem .6rem; font-size: .82rem; }

details.faq { border-top: 1px solid var(--border); }
details.faq summary { padding: .55rem .7rem; cursor: pointer; font-size: .89rem; font-weight: 600; }
details.faq .a { padding: 0 .7rem .7rem; font-size: .89rem; color: var(--muted); white-space: pre-wrap; }

/* ── Guided paste ─────────────────────────────────────────────── */

.guided-start { width: 100%; margin-bottom: .6rem; }

.guided-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .5rem;
}

.guided-bar {
  height: 4px; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; margin-bottom: 1.1rem;
}
#guided-bar-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: var(--accent); transition: width .25s ease;
}

.guided-kicker {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  font-weight: 700; color: var(--muted);
}
.guided-body h2 { font-size: 1.3rem; margin: .15rem 0 .4rem; letter-spacing: -0.01em; }

/* Roomy and readable: this is read at arm's length while switching apps. */
.guided-value {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .9rem;
  white-space: pre-wrap; word-break: break-word;
  font-size: 1.02rem; line-height: 1.5;
  max-height: 42vh; overflow-y: auto;
  margin-bottom: 1.1rem;
}

.guided-actions { display: flex; flex-direction: column; gap: .5rem; }
/* The one button that gets tapped over and over, so it is thumb-sized. */
.guided-actions > .btn-primary { width: 100%; min-height: 54px; font-size: 1rem; }

.guided-done { text-align: center; padding: 1.5rem 0 .5rem; }
.guided-done .row { justify-content: center; }

/* ── Busy overlay, toast, dialog ──────────────────────────────── */

.busy {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  display: grid; place-items: center; padding: 1rem;
}
.busy-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; text-align: center;
  box-shadow: var(--shadow); max-width: 320px; width: 100%;
}
.busy-card p { margin: .9rem 0; font-size: .92rem; }
.spinner {
  width: 32px; height: 32px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 80;
  background: var(--text); color: var(--bg);
  padding: .55rem 1rem; border-radius: 999px; font-size: .87rem; font-weight: 600;
  box-shadow: var(--shadow); pointer-events: none;
}

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 1.15rem; max-width: 440px; width: calc(100% - 2rem);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
