:root {
  --bg: #07070d;
  --bg-2: #0b0b14;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e9e9f1;
  --muted: #9aa0b4;
  --primary: #a855f7;
  --primary-2: #06b6d4;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 0 rgba(255,255,255,0.04) inset, 0 20px 60px -20px rgba(0,0,0,0.6);
  --grad: linear-gradient(135deg, #a855f7 0%, #06b6d4 100%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 80% -20%, #1b1340 0%, transparent 60%),
              radial-gradient(1000px 700px at -10% 10%, #08334a 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.bg-orb {
  position: fixed;
  pointer-events: none;
  filter: blur(80px);
  opacity: 0.6;
  z-index: 0;
}
.orb-1 { width: 520px; height: 520px; background: #7c3aed; border-radius: 50%; top: -180px; right: -160px; }
.orb-2 { width: 460px; height: 460px; background: #06b6d4; border-radius: 50%; top: 30%; left: -200px; opacity: 0.45; }
.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 30%, transparent 75%);
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px clamp(20px, 4vw, 48px);
  background: rgba(7,7,13,0.7);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  box-shadow: 0 10px 30px -10px rgba(168,85,247,0.6);
}
.brand-text h1 {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-size: 18px; margin: 0; letter-spacing: 0.2px;
}
.brand-text span { color: var(--muted); font-size: 12px; }
.topnav { display: flex; gap: 22px; align-items: center; }
.topnav a {
  color: var(--muted); font-size: 14px; font-weight: 500;
  transition: color .2s ease;
}
.topnav a:hover { color: var(--text); }
.topnav .admin-link {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}
.topnav .admin-link:hover { border-color: var(--border-strong); color: var(--text); }

main {
  position: relative; z-index: 1;
  max-width: 1240px; margin: 0 auto;
  padding: clamp(28px, 5vw, 56px) clamp(20px, 4vw, 48px) 80px;
}

.hero { text-align: center; margin: 24px 0 40px; }
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted); margin-bottom: 18px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary-2);
  box-shadow: 0 0 0 4px rgba(6,182,212,0.18);
  animation: pulse 1.6s infinite ease-in-out;
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}
.hero-title {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-size: clamp(28px, 4.4vw, 52px);
  line-height: 1.08; margin: 0 0 14px;
  letter-spacing: -0.02em;
}
.gradient-text {
  display: block;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  max-width: 720px; margin: 0 auto;
  color: var(--muted); font-size: 16px; line-height: 1.6;
}

.generator {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 22px;
  margin-top: 8px;
}
@media (max-width: 980px) {
  .generator { grid-template-columns: 1fr; }
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 22px;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.card-head h3 {
  margin: 0; font-size: 16px; font-weight: 600;
  font-family: 'Space Grotesk', Inter, sans-serif;
}
.muted { color: var(--muted); font-size: 13px; }

.mode-switch {
  display: inline-flex;
  background: rgba(7,7,13,0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
  gap: 4px;
}
.mode-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: linear-gradient(135deg, rgba(168,85,247,0.22), rgba(6,182,212,0.22));
  border-color: rgba(168,85,247,0.55);
  color: var(--text);
  box-shadow: 0 0 0 4px rgba(168,85,247,0.08);
}

.field { margin-bottom: 18px; }
.field label {
  display: block; font-size: 13px; font-weight: 500;
  color: #c8cce0; margin-bottom: 8px;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

textarea, input[type="url"], input[type="text"] {
  width: 100%;
  background: rgba(7,7,13,0.6);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  resize: vertical;
}
textarea:focus, input:focus {
  border-color: rgba(168,85,247,0.55);
  box-shadow: 0 0 0 4px rgba(168,85,247,0.14);
  background: rgba(11,11,20,0.8);
}
.counter {
  text-align: right; font-size: 12px; color: var(--muted); margin-top: 6px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.seg {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.seg-btn {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: all .15s ease;
}
.seg-btn strong { font-size: 15px; }
.seg-btn span { font-size: 11px; color: var(--muted); }
.seg-btn:hover { border-color: var(--border-strong); }
.seg-btn.active {
  background: linear-gradient(135deg, rgba(168,85,247,0.18), rgba(6,182,212,0.18));
  border-color: rgba(168,85,247,0.55);
  box-shadow: 0 0 0 4px rgba(168,85,247,0.10);
}

.ratios {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
@media (max-width: 540px) {
  .ratios { grid-template-columns: repeat(4, 1fr); }
}
.ratio {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text);
  transition: all .15s ease;
}
.ratio:hover { border-color: var(--border-strong); }
.ratio.active {
  background: linear-gradient(135deg, rgba(168,85,247,0.18), rgba(6,182,212,0.18));
  border-color: rgba(168,85,247,0.55);
  box-shadow: 0 0 0 4px rgba(168,85,247,0.10);
}
.r-shape {
  display: block;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 3px;
}
.r-label { font-size: 11px; color: var(--muted); }
.ratio.active .r-label { color: var(--text); }
.ratio.active .r-shape { background: rgba(255,255,255,0.55); }

.img-ratios {
  grid-template-columns: repeat(5, 1fr);
}
@media (max-width: 540px) {
  .img-ratios { grid-template-columns: repeat(3, 1fr); }
}

.r-16-9 { width: 32px; height: 18px; }
.r-9-16 { width: 18px; height: 32px; }
.r-1-1  { width: 24px; height: 24px; }
.r-4-3  { width: 28px; height: 21px; }
.r-3-4  { width: 21px; height: 28px; }
.r-3-2  { width: 30px; height: 20px; }
.r-2-3  { width: 20px; height: 30px; }

.chip-input {
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(7,7,13,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.chip-input:focus-within {
  border-color: rgba(168,85,247,0.55);
  box-shadow: 0 0 0 4px rgba(168,85,247,0.14);
}
.chip-input input { border: none; background: transparent; padding: 6px 4px; box-shadow: none !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(168,85,247,0.14);
  border: 1px solid rgba(168,85,247,0.35);
  color: #e9d8fe;
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  max-width: 100%;
  cursor: pointer;
}
.chip span {
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip::after {
  content: '×';
  font-size: 14px; line-height: 1;
  color: #c4b5fd;
}

.actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 6px;
}
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 600; font-size: 14px;
  cursor: pointer; border: 1px solid transparent;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  color: white;
  background: var(--grad);
  box-shadow: 0 12px 30px -10px rgba(168,85,247,0.55);
}
.btn.primary:hover { box-shadow: 0 16px 40px -10px rgba(168,85,247,0.7); }
.btn.primary:disabled {
  opacity: 0.6; cursor: not-allowed; box-shadow: none;
}
.btn.ghost {
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-color: var(--border);
}
.btn.ghost:hover { border-color: var(--border-strong); background: rgba(255,255,255,0.06); }
.btn.sm { padding: 7px 11px; font-size: 12px; }

.cost-pill {
  margin-left: auto;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px; color: var(--muted);
}
.cost-pill strong { color: var(--text); }

.preview-card { display: flex; flex-direction: column; }
.preview {
  flex: 1;
  min-height: 360px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background:
    radial-gradient(600px 200px at 50% 0%, rgba(168,85,247,0.08), transparent 60%),
    rgba(7,7,13,0.4);
  display: grid; place-items: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.preview.empty .placeholder { display: flex; }
.preview .placeholder, .preview .loading, .preview .result, .preview .errbox { display: none; }
.preview .placeholder {
  flex-direction: column; align-items: center; gap: 14px; color: var(--muted);
  text-align: center;
}
.preview.loading-state .loading { display: flex; flex-direction: column; gap: 18px; align-items: stretch; width: 100%; max-width: 420px; }
.preview.result-state .result { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.preview.error-state .errbox {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center; color: var(--text);
}
.preview.error-state .errbox svg { color: var(--danger); }

.spinner {
  width: 44px; height: 44px; align-self: center;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.08);
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.prog-bar {
  width: 100%; height: 8px; border-radius: 999px;
  background: rgba(255,255,255,0.06); overflow: hidden;
}
.prog-fill {
  height: 100%; width: 0%;
  background: var(--grad);
  transition: width .4s ease;
}
.prog-meta {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 12px; color: var(--muted);
}
.job-info { font-size: 12px; color: var(--muted); text-align: center; }
.job-info code {
  background: rgba(255,255,255,0.06);
  padding: 2px 6px; border-radius: 4px;
}

#videoPlayer {
  width: 100%;
  border-radius: var(--radius-sm);
  background: black;
  display: block;
  max-height: 480px;
}
#imagePlayer {
  width: 100%;
  border-radius: var(--radius-sm);
  background: black;
  display: block;
  max-height: 600px;
  object-fit: contain;
}
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.errbox h4 { margin: 0; font-family: 'Space Grotesk', Inter, sans-serif; }
.errbox p { margin: 0; max-width: 380px; }

.gallery, .guide { margin-top: 56px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 16px; gap: 10px;
}
.section-head h3 {
  margin: 0; font-family: 'Space Grotesk', Inter, sans-serif;
  font-size: 20px;
}
.row-actions { display: flex; align-items: center; gap: 12px; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.empty-history {
  grid-column: 1 / -1;
  text-align: center; color: var(--muted);
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.history-item {
  position: relative;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .15s ease, border-color .15s ease;
}
.history-item:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.history-item video,
.history-item img {
  width: 100%; aspect-ratio: 16/9; background: #000; display: block; object-fit: cover;
}
.history-item .kind-badge {
  position: absolute;
  top: 8px; right: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(255,255,255,0.18);
  color: white;
  backdrop-filter: blur(4px);
}
.history-item .kind-image { background: rgba(168,85,247,0.85); border-color: rgba(168,85,247,0.55); }
.history-item .kind-video { background: rgba(6,182,212,0.85); border-color: rgba(6,182,212,0.55); }
.history-item .h-meta {
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.history-item .h-prompt {
  font-size: 13px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-item .h-foot {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--muted);
}
.history-item .h-foot button {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text); border-radius: 6px;
  padding: 4px 8px; font-size: 11px; cursor: pointer;
}
.history-item .h-foot button:hover { border-color: var(--border-strong); }

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.guide-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.g-num {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-weight: 700; font-size: 14px;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}
.guide-card h4 { margin: 0 0 6px; font-size: 15px; }
.guide-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

footer {
  position: relative; z-index: 1;
  max-width: 1240px; margin: 0 auto;
  padding: 24px clamp(20px, 4vw, 48px);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border);
}
@media (max-width: 600px) {
  footer { flex-direction: column; gap: 6px; }
  .topnav { display: none; }
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(11,11,20,0.95);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 100;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.6);
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(34,197,94,0.45); }
.toast.error { border-color: rgba(239,68,68,0.5); }
