:root {
  --bg: #111117;
  --surface: #17171f;
  --surface-2: #1d1d28;
  --border: #2a2a38;
  --border-strong: #3a3a4c;
  --text: #ececf3;
  --muted: #8d8da2;
  --accent: #8b8cf8;
  --accent-strong: #7072f0;
  --accent-soft: rgba(139, 140, 248, 0.14);
  --warn: #f5b84a;
  --danger: #f87171;
  --ok: #4ade80;
  --tg: #2aabee;
  --radius: 14px;
  --radius-lg: 20px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 28px; font-weight: 600; }
h2 { font-size: 20px; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.accent { color: var(--accent); }
.label { font-size: 13px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px;
  padding: 9px 16px; font: inherit; font-weight: 500; color: var(--text);
  background: var(--surface-2); cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-outline { background: transparent; border-color: var(--border-strong); }
.btn-outline:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent); }
.btn-tg { background: var(--tg); color: #fff; }
.btn-tg:hover { filter: brightness(1.08); }
.btn-lg { padding: 16px 28px; font-size: 20px; font-weight: 600; border-radius: 999px; }
.btn-lg svg { width: 22px; height: 22px; }
.btn-sub { font-size: 14px; font-weight: 500; opacity: 0.8; }

.link-btn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 6px 4px; white-space: nowrap; }
.link-btn:hover { color: var(--text); }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border-radius: 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.tg-icon { width: 22px; height: 22px; stroke: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--topbar-h); padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(17, 17, 23, 0.85); backdrop-filter: blur(10px);
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.credits {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 14px;
}
.credits svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.credits b { color: var(--text); font-weight: 600; }
.credits.bump { animation: bump 0.4s; }
@keyframes bump { 50% { transform: scale(1.12); } }
.user-chip { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; }

/* ---------- landing ---------- */

.landing { max-width: 1240px; margin: 0 auto; padding: 32px 24px 64px; }

.hero {
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 56px; align-items: center;
  padding: 40px 0 72px; border-bottom: 1px solid var(--border);
}
.hero-visual { display: flex; align-items: center; gap: 12px; }
.hero-arrow { width: 32px; height: 32px; color: var(--muted); }
.hero-frame {
  position: relative; flex: 1; aspect-ratio: 9 / 16; max-height: 520px;
  border-radius: var(--radius-lg); overflow: hidden; background: var(--surface);
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
}
.hero-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-frame--video img { animation: kenburns 6s ease-in-out infinite alternate; }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.14) translate(-2%, 1%); } }
.hero-play {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.hero-play svg { width: 56px; height: 56px; fill: #fff; stroke: none; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4)); }
.hero-bar {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 28px 14px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7)); font-size: 13px; color: #fff;
}
.hero-progress { height: 3px; margin-top: 8px; border-radius: 2px; background: rgba(255,255,255,0.25); overflow: hidden; }
.hero-progress::after { content: ''; display: block; height: 100%; width: 0; background: var(--accent); animation: progress 6s linear infinite; }
@keyframes progress { to { width: 100%; } }

.hero-copy { text-align: center; }
.hero-copy h1 { font-size: clamp(36px, 4.4vw, 60px); line-height: 1.1; font-weight: 700; }
.hero-copy h1 .accent { display: block; }
.lead { margin: 20px 0 40px; color: var(--muted); font-size: 18px; }

.how { padding-top: 48px; max-width: 960px; margin: 0 auto; }
.how h2 { margin-bottom: 28px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 32px; }
.steps li { display: flex; gap: 16px; align-items: flex-start; }
.steps b { font-weight: 500; font-size: 16px; }
.steps p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.step-icon {
  display: grid; place-items: center; width: 54px; height: 54px; flex: none;
  border: 1px solid var(--border-strong); border-radius: 14px;
}
.step-icon svg { width: 24px; height: 24px; }

/* ---------- dropzone ---------- */

.dropzone {
  position: relative; display: grid; place-items: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface); transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--surface-2); }
.dropzone--wide { padding: 48px 24px; }
.dropzone-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 16px; }
.dropzone-empty strong { font-weight: 600; font-size: 17px; margin-top: 8px; }
.upload-icon { width: 36px; height: 36px; color: var(--accent); }
.formats { margin-top: 18px; font-size: 12px; color: var(--muted); }
.dropzone.has-image { border-style: solid; border-color: var(--border); cursor: default; }
.dropzone-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.dropzone-clear { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.55); color: #fff; }
.dropzone-clear:hover { background: rgba(0,0,0,0.75); color: #fff; }

/* ---------- app layout ---------- */

.app { display: grid; grid-template-columns: 248px 1fr; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
  border-right: 1px solid var(--border); padding: 8px 14px 24px;
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
}
.sidebar-head { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 6px 12px; font-weight: 600; font-size: 14px; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.hist-item {
  display: block; padding: 10px; border-radius: var(--radius); text-decoration: none;
  border: 1px solid transparent; transition: background 0.15s;
}
.hist-item:hover { background: var(--surface); }
.hist-item.active { background: var(--surface-2); border-color: var(--border); }
.hist-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 8px; }
.hist-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.hist-time.soon { color: var(--warn); }
.hist-thumbs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; }
.hist-thumbs > svg { width: 14px; height: 14px; color: var(--muted); }
.thumb {
  aspect-ratio: 9 / 16; border-radius: 8px; overflow: hidden; background: var(--surface);
  border: 1px solid var(--border); display: grid; place-items: center;
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .spinner { width: 20px; height: 20px; border-width: 2px; }
.thumb.failed { color: var(--danger); }

.new-card {
  margin-top: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 104px; border: 1.5px solid var(--border-strong); border-radius: var(--radius);
  text-decoration: none; color: var(--muted); font-size: 13px; transition: all 0.15s;
}
.new-card svg { width: 30px; height: 30px; stroke-width: 1.5; }
.new-card:hover { color: var(--text); border-color: var(--muted); }
.new-card.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

.workspace { padding: 28px 40px 48px; min-width: 0; }
.view {
  display: grid; gap: 48px; align-items: start;
  /* 9:16 frames sized so the button under them stays above the fold */
  --frame-w: min(100%, max(220px, calc((100dvh - 330px) * 0.5625)));
}
.view-new { grid-template-columns: minmax(260px, 380px) minmax(260px, 340px); justify-content: space-between; max-width: 1100px; }
.view-video { grid-template-columns: minmax(260px, 380px) minmax(240px, 420px); }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.frame {
  aspect-ratio: 9 / 16; width: var(--frame-w, 100%); border-radius: var(--radius-lg); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
}
.frame video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 14px; color: var(--muted); }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ''; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}
select {
  width: 100%; appearance: none; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 12px 40px 12px 14px; cursor: pointer;
}
select:hover { border-color: var(--muted); }
/* left column starts at the very top; right column keeps its "Your image" heading lower */
.view-new { margin-top: -20px; }
.view-new .col-right { padding-top: 20px; }

.col-right #generate-btn { width: var(--frame-w); margin-top: 8px; }
.col-right #generate-hint { width: var(--frame-w); }

/* ---------- result view ---------- */

.result-frame { position: relative; }
.result-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center; background: var(--surface);
}
.result-overlay.failed .spinner { display: none; }
.result-overlay.failed strong { color: var(--danger); }

.download-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.countdown { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.countdown b { color: var(--text); font-weight: 600; }
.countdown.soon, .countdown.soon b { color: var(--warn); }

.note {
  margin-top: 64px; padding: 20px 22px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px;
}
.note-title { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; color: var(--warn); }
.note-title svg { width: 24px; height: 24px; }
.note p { font-size: 16px; color: #cfcfdc; }
.source { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.source img { width: 96px; aspect-ratio: 9 / 16; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }

/* ---------- spinner ---------- */

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dot-pulse { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---------- modals ---------- */

.modal {
  width: min(420px, calc(100vw - 32px)); padding: 36px 32px 28px;
  border: 1px solid var(--border-strong); border-radius: 32px;
  background: #121218; color: var(--text); text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal::backdrop { background: rgba(8, 8, 12, 0.55); backdrop-filter: blur(10px); }
.modal[open] { animation: pop 0.18s ease-out; }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
.modal h2 { font-size: 24px; line-height: 1.3; }
.modal > p { margin-top: 12px; }
.modal-close { position: absolute; top: 14px; right: 14px; }
#signin-link { margin-top: 24px; width: 100%; font-size: 17px; }
.waiting { margin-top: 16px; display: flex; justify-content: center; align-items: center; gap: 8px; }

.pay-options { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.pay-options .btn {
  width: 100%; padding: 14px; font-size: 17px; border-radius: 14px;
  background: transparent; border: 1.5px solid var(--border-strong);
}
.pay-options .btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.pay-qr { margin-top: 20px; width: 220px; max-width: 100%; border-radius: 12px; background: #fff; padding: 8px; }

/* ---------- toasts ---------- */

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border-strong);
  font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); animation: toast-in 0.2s ease-out;
}
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
.toast.ok { border-color: rgba(74, 222, 128, 0.4); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; gap: 40px; padding-top: 16px; }
  .hero-visual { max-width: 520px; margin: 0 auto; width: 100%; }
  .workspace { padding: 24px; }
  .view-new, .view-video { grid-template-columns: 1fr; max-width: 420px; gap: 32px; --frame-w: 100%; }
  .view-new { margin-top: 0; }
  .view-new .col-right { padding-top: 0; }
  .note { margin-top: 0; }
}

@media (max-width: 720px) {
  .topbar { padding: 0 16px; }
  .logo { font-size: 17px; gap: 8px; }
  .logo img { width: 24px; height: 24px; }
  .user-chip > span { display: none; }
  .topbar-right { gap: 8px; }
  .landing { padding: 16px 16px 48px; }
  .steps { grid-template-columns: 1fr; gap: 20px; }

  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border);
    padding: 8px 16px 12px; display: flex; gap: 8px; overflow-x: auto; align-items: stretch;
  }
  .sidebar-head { display: none; }
  .history { flex-direction: row; gap: 8px; }
  .hist-item { width: 132px; }
  .new-card { margin-top: 0; width: 96px; height: auto; min-height: 120px; flex: none; }
  .workspace { padding: 20px 16px 40px; }
  .view-new, .view-video { max-width: none; }
  h1 { font-size: 24px; }
}
.btn.disabled { opacity: 0.45; pointer-events: none; }
