/* =========================================================
   GEXI — Create (content-pipeline front door)

   A thin, mobile-correct PAGE LAYER on the shared design system. It consumes the
   brand tokens from styles.css (brand color, accent, card, line, ink, muted,
   shadow and radius scales) and the gx-ui kit's motion + radius
   (gx-grad/gx-ease/gx-r) — NO parallel color system — so Create inherits the
   exact "Gemini-grade, GEXI-green" look + dark mode the homepage uses, and a future
   rewrite can adopt the .gx-* primitives directly. Class names stay fd-* so the
   proven frontdoor.js (and its e2e) keep binding unchanged.

   MOBILE-CORRECTNESS CONTRACT (the inherited "right side cut off" bug — fixed at the
   root, documented so it never returns):
   • <body> is a flex COLUMN (global app shell). A max-width container that is a flex
     child MUST also set `width:100%; min-width:0` or its min-content floor refuses to
     shrink below the desktop max-width and `overflow-x:clip` silently cuts it off.
     → .fd-main does exactly that. Every full-width scroll strip uses min-width:0.
   • Horizontal chip/example rows NEVER wrap-overflow on phones: they become swipeable
     scroll strips (overflow-x:auto, scroll-snap), bounded to the viewport.
   ========================================================= */

:root {
  /* Map the page's local aliases onto the shared brand tokens (single source of
     truth). Older fd-* rules reference these; now they pull the brand system. */
  --fd-accent:   var(--brand-500);
  --fd-accent-2: var(--accent);
  --fd-radius:   var(--gx-r, 18px);
  --fd-line:     var(--line);
  --fd-surface:  var(--card-alt);
  --fd-grad:     var(--grad-creative);   /* P2 — collapse onto the single canonical brand gradient (styles.css) */
  --fd-ease:     var(--gx-ease, cubic-bezier(.2, .7, .3, 1));
}

/* ---- header ---- */
.fd-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
}
.fd-home { color: var(--brand-500); font-weight: 700; text-decoration: none; font-size: 15px; }
.fd-home:hover { text-decoration: underline; }
.fd-title { font-weight: 650; color: var(--muted); }
.fd-spacer { flex: 1; }
/* UC5a-2 — the Switch-mode handoff trigger (hidden until the unified flag is feature-detected on).
   Distinct from the pre-existing .fd-switch (plan-card suggested-switch hint) + .fd-switch-btn. */
.fd-mode-switch { appearance: none; background: transparent; border: 0; cursor: pointer; padding: 0; color: var(--brand-500); font-weight: 700; font-size: 15px; font-family: inherit; }
.fd-mode-switch:hover { text-decoration: underline; }

/* ---- page canvas (the mobile-correctness keystone) ---- */
.fd-main {
  max-width: 760px; width: 100%; min-width: 0; box-sizing: border-box;
  margin-inline: auto; padding: clamp(20px, 5vw, 44px) 16px 96px;
}
.fd-h1 {
  font-size: clamp(24px, 5.4vw, 34px); font-weight: 800; margin: 0 0 8px;
  line-height: 1.14; letter-spacing: -0.022em;
  /* Every step heading uses the brand gradient — one consistent, premium voice. */
  background: var(--fd-grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  padding-bottom: 1px;   /* keeps gradient descenders (g/p/y) from clipping */
}
.fd-sub { margin: 0 0 24px; font-size: clamp(15px, 2vw, 16px); color: var(--muted); line-height: 1.5; }

.fd-step { animation: fd-rise .42s var(--fd-ease) both; }

/* ---- START: a tight, top-aligned, centered hero (homepage-grade) ---- */
#fd-start { padding-top: clamp(4px, 2vh, 18px); }
.fd-hero { text-align: center; }
.fd-hero .fd-sub { margin: 0 auto 20px; max-width: 44ch; }

/* the Gemini-style prompt card — prominent rounded input + integrated send button */
/* P2.4 — the prompt card now lives ONCE as .gx-promptcard in gx-ui.css (create.html consumes it,
   keeping #fd-desc / #fd-plan-btn). The old .fd-promptcard rules were retired here. */

/* quiet "or pick a starting point" divider */
.fd-or {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  margin: 24px auto 14px; max-width: 600px; color: var(--muted);
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
}
.fd-or::before, .fd-or::after { content: ''; height: 1px; flex: 1; background: var(--line); max-width: 110px; }

/* chips/examples centered in the focused hero (desktop); left-scroll strip on phones */
.fd-hero .fd-chips, .fd-hero .fd-examples { justify-content: center; }
@media (max-width: 640px) {
  .fd-hero .fd-chips, .fd-hero .fd-examples { justify-content: flex-start; }
}

/* ---- output-type chips ---- */
.fd-chips { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 18px; min-width: 0; }
@media (max-width: 640px) {
  /* swipeable scroll strip — bounded to the viewport, never overflows the page */
  .fd-chips {
    flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch; padding-bottom: 4px;
    margin-inline: -16px; padding-inline: 16px;
  }
  .fd-chips::-webkit-scrollbar { display: none; }
  .fd-chip { scroll-snap-align: start; flex: 0 0 auto; }
}
.fd-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-pill); cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  font-size: 14px; font-weight: 650; white-space: nowrap;
  transition: background .16s, border-color .16s, transform .1s var(--fd-ease), box-shadow .16s;
}
.fd-chip .fd-chip-ico { font-size: 17px; line-height: 1; }
.fd-chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.fd-chip:active { transform: scale(0.96); }
.fd-chip.is-active {
  background: var(--fd-grad); color: #fff; border-color: transparent; box-shadow: var(--shadow-md);
}

/* ---- describe ---- */
.fd-textarea {
  width: 100%; box-sizing: border-box; resize: vertical;
  padding: 15px 16px; border-radius: var(--gx-r, 18px); font-family: inherit; font-size: 16px; line-height: 1.5;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow); transition: border-color .16s, box-shadow .16s;
}
.fd-textarea::placeholder { color: var(--muted); }
.fd-textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-glow); }
.fd-textarea-sm { font-size: 14.5px; }

/* example idea chips */
.fd-examples { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; min-width: 0; }
@media (max-width: 640px) {
  .fd-examples {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity; margin-inline: -16px; padding: 0 16px 4px;
  }
  .fd-examples::-webkit-scrollbar { display: none; }
  .fd-example { scroll-snap-align: start; flex: 0 0 auto; }
}
.fd-example {
  font-size: 13px; padding: 8px 13px; border-radius: var(--radius-pill); cursor: pointer;
  border: 1px dashed var(--line-strong); background: transparent; color: var(--muted);
  white-space: nowrap; transition: border-color .16s, color .16s, background .16s;
}
.fd-example:hover { color: var(--ink); border-color: var(--accent); background: var(--grad-brand-soft); }

/* ---- buttons ---- */
.fd-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; min-width: 0; }
.fd-hero .fd-actions { justify-content: center; }
.fd-btn {
  flex: 1; min-width: 0; padding: 14px 20px; border-radius: var(--radius-pill); font-size: 15px; font-weight: 700;
  cursor: pointer; border: 1.5px solid transparent; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter .16s, transform .1s var(--fd-ease), box-shadow .16s, border-color .16s;
}
.fd-btn-lg { flex: 0 1 340px; padding: 15px 24px; font-size: 16px; }
.fd-btn:active { transform: translateY(1px); }
.fd-btn-primary { background: var(--fd-grad); color: #fff; box-shadow: var(--shadow-md); }
.fd-btn-primary:hover { filter: brightness(1.05); }
.fd-btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; filter: none; }
.fd-btn-ghost { flex: 0 0 auto; background: transparent; border-color: var(--line-strong); color: var(--ink); }
.fd-btn-ghost:hover { border-color: var(--accent); }
/* C4 — cost-confirm gate. It renders inside .fd-build-grid (a grid), so span all columns or
   it gets squished into one 150px cell (buttons collapse to circles). */
.fd-confirm { grid-column: 1 / -1; text-align: center; padding: 10px 4px; max-width: 460px; margin: 0 auto; }
.fd-confirm-cost { font-size: 16px; margin: 6px 0 4px; }
.fd-confirm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.fd-confirm-actions .fd-btn { flex: 0 1 auto; min-width: 132px; white-space: nowrap; }

.fd-error { margin-top: 12px; color: var(--red); font-size: 14px; }

/* ---- plan card ---- */
.fd-plancard {
  border: 1px solid var(--line); border-radius: var(--gx-r, 18px); padding: 20px;
  background: var(--card); box-shadow: var(--shadow);
}
.fd-pc-summary { font-size: 18px; font-weight: 750; line-height: 1.35; color: var(--ink); }
.fd-pc-summary .fd-pc-ico { font-size: 22px; margin-right: 6px; }
.fd-pc-summary .fd-pc-dim { color: var(--muted); font-weight: 600; font-size: 15px; }

/* stage stepper */
.fd-pc-steps { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 14px; }
.fd-step-chip { font-size: 12px; font-weight: 650; padding: 5px 11px; border-radius: var(--radius-pill); background: var(--grad-brand-soft); color: var(--brand-500); }
.fd-step-sep { color: var(--muted); opacity: 0.6; font-size: 12px; }

.fd-pc-tweak { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.fd-pc-tweak-toggle { cursor: pointer; font-size: 13.5px; font-weight: 650; color: var(--muted); list-style: none; }
.fd-pc-tweak-toggle::-webkit-details-marker { display: none; }
.fd-pc-tweak-toggle::before { content: '⚙ '; }
.fd-pc-body { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.fd-pc-row { display: flex; flex-direction: column; gap: 6px; }
.fd-pc-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.fd-pc-field { display: flex; flex-direction: column; gap: 6px; }
.fd-pc-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.fd-select, .fd-input {
  padding: 11px 12px; border-radius: 12px; font-family: inherit; font-size: 15px; color: var(--ink);
  border: 1.5px solid var(--line); background: var(--card); width: 100%; box-sizing: border-box;
  transition: border-color .16s, box-shadow .16s;
}
.fd-select:focus, .fd-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-glow); }

/* style preview */
.fd-preview-frame { max-width: 420px; margin: 6px auto 2px; border-radius: var(--gx-r, 18px); overflow: hidden; }
.fd-preview-frame .fd-tile { aspect-ratio: 1; max-width: 420px; }
.fd-preview-img { width: 100%; display: block; border-radius: var(--gx-r, 18px); border: 1px solid var(--line); animation: fd-fade 380ms ease; }

.fd-switch { margin-bottom: 14px; font-size: 14px; padding: 11px 14px; border-radius: 12px; background: rgba(251,191,36,0.15); border: 1px solid rgba(251,191,36,0.3); color: var(--ink); }
.fd-switch-btn { background: none; border: none; color: var(--brand-500); font-weight: 750; cursor: pointer; padding: 0; text-decoration: underline; }

/* ---- build (progress + results, in place) ---- */
.fd-build-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.fd-build-count { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fd-progressbar { height: 8px; border-radius: var(--radius-pill); background: var(--card-alt); overflow: hidden; margin: 14px 0 18px; }
.fd-progressbar-fill { height: 100%; width: 0; border-radius: var(--radius-pill); background: var(--fd-grad); transition: width 400ms ease; }

.fd-build-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; min-width: 0; }
@media (max-width: 440px) { .fd-build-grid { grid-template-columns: 1fr 1fr; } }
.fd-tile {
  aspect-ratio: 1; border-radius: 15px; overflow: hidden; position: relative;
  background: var(--card-alt); display: grid; place-items: center;
  border: 1px solid var(--line);
}
.fd-tile img { width: 100%; height: 100%; object-fit: cover; display: block; animation: fd-fade 380ms ease; }
.fd-tile.is-error { border-color: var(--red); }
.fd-tile-ph { display: grid; place-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.fd-tile.is-pending::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(127,127,127,0.16) 50%, transparent 70%);
  background-size: 200% 100%; animation: fd-shimmer 1.3s ease-in-out infinite;
}
.fd-spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--brand-500); animation: fd-spin 0.8s linear infinite; }

/* P1.7 per-scene controls */
.fd-tile-actions {
  position: absolute; top: 7px; right: 7px; display: flex; gap: 6px; z-index: 2;
  opacity: 0; transition: opacity 140ms ease;
}
.fd-tile:hover .fd-tile-actions, .fd-tile:focus-within .fd-tile-actions { opacity: 1; }
@media (hover: none) { .fd-tile-actions { opacity: 1; } }
.fd-tile-btn {
  width: 30px; height: 30px; border-radius: 9px; border: none; cursor: pointer;
  background: rgba(15,17,21,0.66); color: #fff; font-size: 14px; line-height: 1;
  display: grid; place-items: center; backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px); transition: background 120ms ease, transform 120ms ease;
}
.fd-tile-btn:hover { background: rgba(15,17,21,0.85); transform: translateY(-1px); }
.fd-tile-btn:active { transform: none; }

.fd-tile-editor {
  position: absolute; inset: 0; z-index: 3; padding: 10px; display: flex; flex-direction: column; gap: 5px;
  background: var(--card); border-radius: 15px; overflow: auto; animation: fd-fade 160ms ease;
}
.fd-ed-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.fd-tile-editor textarea {
  width: 100%; resize: none; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card-alt); color: var(--ink); padding: 6px 8px; font: inherit; font-size: 12.5px; line-height: 1.4;
}
.fd-ed-row { display: flex; gap: 6px; margin-top: auto; }
.fd-ed-btn { flex: 1; padding: 7px; border-radius: 9px; border: 1px solid var(--line); cursor: pointer; font-size: 12.5px; font-weight: 600; background: transparent; color: var(--ink); }
.fd-ed-save, .fd-st-save { background: var(--brand-500); border-color: var(--brand-500); color: #fff; }
.fd-ed-save:disabled, .fd-st-save:disabled { opacity: 0.5; cursor: default; }

/* P3.6c — per-scene light-edit styler */
.fd-tile-btn.is-on { background: var(--brand-500); color: #fff; }
.fd-styler .fd-st-filter, .fd-styler .fd-st-dur {
  width: 100%; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card-alt); color: var(--ink); padding: 6px 8px; font: inherit; font-size: 12.5px;
}
.fd-st-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.fd-st-check input { margin: 0; }
.fd-styler textarea:disabled { opacity: 0.45; }
.fd-st-err { color: var(--red); font-size: 11.5px; line-height: 1.35; }
.fd-note { grid-column: 1 / -1; padding: 18px; border-radius: 15px; background: var(--card-alt); font-size: 14.5px; line-height: 1.55; display: flex; gap: 10px; align-items: center; color: var(--ink); }
.fd-note .fd-doc { display: block; white-space: pre-wrap; margin: 0; font: inherit; line-height: 1.6; width: 100%; }
.fd-note-info { background: color-mix(in srgb, var(--accent) 12%, var(--card-alt)); border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent); font-size: 13.5px; padding: 12px 15px; margin-bottom: 10px; }

@keyframes fd-fade { from { opacity: 0; transform: scale(1.02); } to { opacity: 1; transform: none; } }
@keyframes fd-rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fd-spin { to { transform: rotate(360deg); } }
@keyframes fd-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .fd-step, .fd-tile.is-pending::after, .fd-spinner, .fd-tile img, .fd-producer { animation: none !important; }
}

/* P3.5 — the compiled result */
.fd-result { margin: 16px 0 8px; display: flex; justify-content: center; animation: fd-fade 240ms ease; }
.fd-result-video { width: 100%; max-width: 420px; max-height: 70vh; border-radius: 16px; background: #000; box-shadow: var(--shadow-lg); }
.fd-result-img { width: 100%; max-width: 420px; border-radius: 16px; display: block; box-shadow: var(--shadow-md); }
.fd-result-audio { width: 100%; max-width: 420px; }
#fd-download-btn { text-decoration: none; }

/* disabled state */
.fd-disabled { padding: 48px 0; }
.fd-disabled-card { border: 1px dashed var(--line-strong); border-radius: var(--gx-r, 18px); padding: 28px; text-align: center; color: var(--ink); }
.fd-disabled-card code { background: var(--card-alt); padding: 2px 7px; border-radius: 6px; }

/* P4 — the "Let GEXI finish it" hero button (autonomous Producer) — purple→blue→lime
   to read as distinct from the green primary action. */
.fd-btn-magic {
  background: linear-gradient(135deg, #7c3aed, #2563eb 55%, var(--accent-2));
  color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(124,58,237,0.32);
}
.fd-btn-magic:hover { filter: brightness(1.06); }
.fd-btn-magic:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* P4 — the live Producer status strip */
.fd-producer {
  margin: 12px 0 4px; padding: 13px 15px; border-radius: 14px; font-size: 14.5px; line-height: 1.5;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); animation: fd-fade 240ms ease;
}
.fd-producer-line { display: flex; gap: 9px; align-items: center; }
.fd-producer-vision { margin-top: 7px; font-size: 13.5px; font-style: italic; color: var(--muted); }
.fd-producer.is-running { border-color: rgba(37,99,235,0.4); background: rgba(37,99,235,0.07); }
.fd-producer.is-running .fd-spinner { border-top-color: #2563eb; }
.fd-producer.is-paused { border-color: rgba(251,191,36,0.45); background: rgba(251,191,36,0.10); }
.fd-producer.is-escalated { border-color: rgba(251,191,36,0.5); background: rgba(251,191,36,0.12); }
.fd-producer.is-done { border-color: rgba(22,163,74,0.4); background: rgba(34,197,94,0.09); }

/* P2 — the quiet automatic-quality-review summary + flagged tiles */
.fd-review-summary { margin: 8px 0 2px; font-size: 13.5px; font-weight: 600; }
.fd-review-summary.all-ok { color: var(--brand-500); }
.fd-review-summary.has-flags { color: #b45309; }
.fd-tile.is-flagged { outline: 2px solid #f59e0b; outline-offset: 1px; }
.fd-tile.is-flagged::before {
  content: '⚠︎'; position: absolute; top: 5px; left: 5px; z-index: 2;
  font-size: 12px; line-height: 1; padding: 3px 5px; border-radius: 7px;
  background: rgba(245,158,11,0.92); color: #1a1206;
}

@media (max-width: 440px) { .fd-pc-grid { grid-template-columns: 1fr; } }

/* F2 — compose-ladder verdict badges (only the user-meaningful ones) */
.fd-tile-sel {
  position: absolute; left: 6px; bottom: 6px; z-index: 2;
  font-size: 10.5px; font-weight: 800; letter-spacing: .01em; white-space: nowrap;
  color: #fff; border-radius: 999px; padding: 3px 8px; pointer-events: auto;
  background: rgba(17, 24, 39, .78); backdrop-filter: blur(4px);
}
.fd-tile-sel.is-upgrade { background: linear-gradient(135deg, rgba(16,185,129,.92), rgba(132,204,22,.92)); }
.fd-tile-sel.is-rescue { background: rgba(180, 83, 9, .9); }
.fd-tile-sel.fd-tile-sel-voice { left: auto; right: 6px; padding: 3px 6px; }   /* F1: the narration marker sits opposite the visual badge */

/* F4 — the instant-serve choice card (the honest lightning/fresh offer) */
.fd-instant {
  display: flex; gap: 12px; align-items: center; margin-bottom: 14px; padding: 12px;
  border-radius: 14px; border: 1px solid rgba(16,185,129,.35);
  background: linear-gradient(135deg, rgba(16,185,129,.08), rgba(132,204,22,.08));
}
.fd-instant-thumb { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; flex: none; border: 1px solid var(--line); }
.fd-instant-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; width: 100%; }
.fd-instant-body strong { font-size: 14px; color: var(--ink); }
.fd-instant-sub { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.fd-instant-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.fd-instant-actions .fd-btn { padding: 8px 14px; font-size: 13px; }

/* F4 v2 — the slate rail (pick-one-of-N instant options) */
.fd-slate { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 6px; -webkit-overflow-scrolling: touch; }
.fd-slate-item {
  position: relative; flex: none; width: 86px; height: 86px; padding: 0;
  border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--card-alt);
  border: 2px solid var(--line); transition: border-color .15s ease, transform .15s ease;
}
.fd-slate-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fd-slate-item.is-selected { border-color: var(--brand-500); transform: scale(1.04); }
.fd-slate-src {
  position: absolute; left: 4px; bottom: 4px; font-size: 9px; font-weight: 800; color: #fff;
  background: rgba(17,24,39,.78); border-radius: 999px; padding: 2px 6px; white-space: nowrap;
}
.fd-slate-src.is-gexi { background: linear-gradient(135deg, rgba(16,185,129,.92), rgba(132,204,22,.92)); }
