:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #16151a;
  --muted: #6b6873;
  --line: #e2dfd8;
  --accent: #5b3df5;
  --accent-ink: #ffffff;
  --accent-soft: #ece8ff;
  --yellow: #ffe14d;
  --ok: #1a7f4b;
  --ok-soft: #e3f4ea;
  --warn: #9a6400;
  --warn-soft: #fbf0d9;
  --error: #b42318;
  --error-soft: #fde8e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 18, 30, 0.05), 0 8px 24px rgba(20, 18, 30, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111016;
    --surface: #1a1920;
    --surface-2: #24222b;
    --text: #f2f0f6;
    --muted: #a19eab;
    --line: #2e2c36;
    --accent: #8f7bff;
    --accent-ink: #0e0c16;
    --accent-soft: #2a2442;
    --ok: #5fd39a;
    --ok-soft: #173325;
    --warn: #f0bf5a;
    --warn-soft: #3a2d12;
    --error: #ff8a80;
    --error-soft: #3d1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 Manrope, system-ui, -apple-system, sans-serif;
}
h1, h2 { line-height: 1.15; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: clamp(28px, 4.2vw, 44px); font-weight: 800; }
h2 { font-size: 20px; font-weight: 800; }
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px 80px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, calc((100vw - 1180px) / 2 + 16px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; text-decoration: none; letter-spacing: -0.02em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); position: relative; }
.brand-mark::after {
  content: ''; position: absolute; left: 10px; top: 7px;
  border-left: 11px solid var(--yellow); border-top: 7px solid transparent; border-bottom: 7px solid transparent;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--text) 30%, var(--line)); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.ghost { background: transparent; }
.btn.small { height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { height: 56px; padding: 0 28px; font-size: 17px; border-radius: 12px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.pill { display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; }
.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--error-soft); color: var(--error); }
.badge.wait { background: var(--surface-2); color: var(--muted); }

/* hero */
.hero { padding: 44px 0 24px; max-width: 760px; }
.lead { font-size: 18px; color: var(--muted); margin: 14px 0 0; }

/* builder */
.builder { display: grid; gap: 16px; max-width: 760px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { flex: 1; }
.step { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--text); color: var(--bg); font-weight: 800; font-size: 14px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
input, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 11px 13px; font-size: 16px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
input { height: 44px; }
textarea { resize: vertical; min-height: 88px; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 12px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; height: 1px; background: var(--line); flex: 1; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #fff; border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: contain; }
.photo.main { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-tag, .photo-main {
  position: absolute; left: 6px; bottom: 6px; font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 6px;
  background: var(--accent); color: var(--accent-ink); border: 0;
}
.photo-main { background: rgba(20, 18, 30, 0.72); color: #fff; cursor: pointer; opacity: 0; transition: opacity 0.15s; }
.photo:hover .photo-main, .photo-main:focus-visible { opacity: 1; }
.photo-x {
  position: absolute; right: 6px; top: 6px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(20, 18, 30, 0.72); color: #fff; font-size: 17px; line-height: 1; cursor: pointer;
}
.dropzone {
  aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 12px; display: grid; place-content: center; justify-items: center; gap: 2px;
  cursor: pointer; text-align: center; font-weight: 700; font-size: 14px; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-plus { font-size: 26px; line-height: 1; color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg);
  font-weight: 700; font-size: 14px; cursor: pointer; transition: all 0.12s;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg-btn {
  min-height: 44px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; font-size: 14px; cursor: pointer;
  display: grid; place-content: center; line-height: 1.2; padding: 6px 8px;
}
.seg-btn.on { background: var(--surface); box-shadow: var(--shadow); }
.seg-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.seg-note { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.submit-row { display: flex; justify-content: flex-end; }

/* projects list */
.projects { margin-top: 48px; display: grid; gap: 16px; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.project-card {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: center; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.project-card:hover { border-color: var(--accent); }
.project-card img { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 8px; }
.project-card div { display: grid; gap: 3px; justify-items: start; }
.project-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* project view */
.back { display: inline-block; margin: 24px 0 12px; text-decoration: none; color: var(--muted); font-weight: 700; }
.project-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.project-head h1 { font-size: clamp(24px, 3.4vw, 34px); }
.meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.price { font-weight: 800; font-size: 18px; }
.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.clip { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 10px; align-content: start; }
.clip-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 2px; }
.clip-style { font-weight: 800; font-size: 14px; }
.clip-stage { position: relative; aspect-ratio: 9 / 16; border-radius: 10px; overflow: hidden; background: #0f0f13; }
.clip-canvas { width: 100%; height: 100%; display: block; cursor: pointer; }
.clip-overlay {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center; padding: 14px;
  color: #fff; font-weight: 700; font-size: 14px; background: #16151a;
}
.clip-overlay.light { background: rgba(15, 15, 19, 0.5); }
.clip.failed .clip-overlay { background: #2a1512; }
.clip-overlay .small { font-weight: 500; opacity: 0.8; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: var(--yellow); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.play {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; transform: translate(-50%, -50%); border-radius: 50%; border: 0;
  background: rgba(15, 15, 19, 0.62); cursor: pointer; display: grid; place-items: center; transition: transform 0.12s, background 0.12s;
}
.play:hover { background: var(--accent); transform: translate(-50%, -50%) scale(1.06); }
.play-icon { width: 0; height: 0; margin-left: 5px; border-left: 20px solid #fff; border-top: 12px solid transparent; border-bottom: 12px solid transparent; }
.export-bar { position: absolute; left: 10px; right: 10px; bottom: 10px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.export-bar span { display: block; height: 100%; width: 0; background: var(--yellow); transition: width 0.2s linear; }
.clip-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.clip-actions .btn { flex: 1; }
.edit { display: grid; gap: 10px; }
.edit input { height: 40px; font-size: 14px; }
.edit textarea { font-size: 14px; min-height: 76px; }
.export-note { margin-top: 18px; }

/* dialog + toast */
.dialog { border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 10, 14, 0.45); }
.dialog form { display: grid; gap: 12px; }
.dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--error); font-weight: 600; margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow); transition: opacity 0.4s, transform 0.4s;
}
.toast.error { background: var(--error); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.out { opacity: 0; transform: translate(-50%, 10px); }

@media (max-width: 640px) {
  .hero { padding-top: 28px; }
  .grid2 { grid-template-columns: 1fr; }
  .row { flex-direction: column; }
  .seg { grid-auto-flow: row; }
  .clip-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .clip-actions .btn { flex: 1 1 100%; }
  .submit-row .btn { width: 100%; }
}

/* product / business switch */
.kind-pick { display: grid; gap: 8px; max-width: 760px; margin-bottom: 16px; }
.kind-label { font-weight: 800; font-size: 15px; }

/* business form */
.links { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.callout { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-size: 14px; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }
.sources { display: grid; gap: 6px; }
.source { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.source-url { font-weight: 600; overflow-wrap: anywhere; }
.brief { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.brief .wide { grid-column: 1 / -1; }
.angles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.angle {
  display: grid; gap: 4px; text-align: left; padding: 12px 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); transition: all 0.12s;
}
.angle strong { font-size: 15px; }
.angle span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.angle.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
@media (max-width: 640px) {
  .brief { grid-template-columns: 1fr; }
}
