:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222e;
  --border: #2a2f3d;
  --text: #e7e9ee;
  --muted: #9aa1b1;
  --accent: #6d8bff;
  --accent-2: #4cc38a;
  --danger: #e5658b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 28px 32px 8px;
}

header h1 {
  margin: 0;
  font-size: 24px;  letter-spacing: 0.2px;
}

.tag {
  color: var(--muted);
  margin: 6px 0 0;
  max-width: 720px;
}

main {
  display: block;
  padding: 20px 32px 48px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.controls {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

label { font-size: 13px; color: var(--muted); }
.hint { color: #6b7280; font-weight: 400; }

select, input[type="text"], input[type="number"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

select:focus, input:focus { border-color: var(--accent); }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s ease, transform 0.05s ease;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.primary { background: var(--accent); color: white; }
.note { font-size: 12px; color: var(--muted); margin: 0; }

.status { color: var(--muted); min-height: 22px; margin-bottom: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card .media { background: #0a0c11; aspect-ratio: 9 / 16; display: block; width: 100%; object-fit: cover; }

.card .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.card .meta { font-size: 12px; color: var(--muted); }
.card .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; font-size: 11px; color: var(--muted); }

.move-category { display: flex; align-items: center; gap: 8px; }
.move-category select { flex: 1; min-width: 0; font-size: 12px; padding: 4px 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.move-status { font-size: 11px; color: var(--muted); white-space: nowrap; }

.anim-input { width: 100%; box-sizing: border-box; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--text); resize: vertical; font-family: inherit; }
.anim-input::placeholder { color: var(--muted); }

/* ------ Create-mode tabs (Generate with AI / Upload image) ------ */
.mode-tabs {
  display: flex;
  gap: 4px;
  margin: 4px 0 14px;
  border-bottom: 1px solid var(--border);
}
.mode-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.mode-panel { display: none; flex-direction: column; gap: 14px; }
.mode-panel.active { display: flex; }
.mode-panel textarea,
#style-description,
.modify-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  resize: vertical;
  font-family: inherit;
}
.mode-panel input[type="file"] { font-size: 13px; color: var(--text); }

/* ------ Paste-image zone (Upload mode) ------ */
.paste-zone {
  position: relative;
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.paste-zone:hover,
.paste-zone:focus,
.paste-zone.dragover { border-color: var(--accent); background: var(--panel-2); outline: none; }
.paste-zone-text { font-size: 12px; color: var(--muted); }
.paste-zone kbd {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: inherit;
}
.paste-preview { max-width: 100%; max-height: 160px; border-radius: 6px; display: block; }
.paste-preview[hidden] { display: none; }
.paste-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  justify-content: flex-start;
}
.paste-thumbs[hidden] { display: none; }
.paste-thumb { position: relative; width: 72px; height: 72px; }
.paste-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.paste-thumb .paste-clear {
  position: absolute;
  top: -6px;
  right: -6px;
}
.paste-clear {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.paste-clear:hover { background: var(--danger); }

/* ------ Per-card edit tabs (Modify / Generate video) ------ */
.card-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.card-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
}
.card-tab:hover { color: var(--text); }
.card-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.card-panel { display: none; flex-direction: column; gap: 8px; }
.card-panel.active { display: flex; }
.modify-input::placeholder { color: var(--muted); }

.actions { display: flex; gap: 8px; }
.actions button { flex: 1; }
.keep { background: var(--accent-2); color: #04291b; }
.discard { background: transparent; border: 1px solid var(--border); color: var(--danger); }
.rerender { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.review { display: flex; flex-direction: column; gap: 8px; }
.preview-hint { margin: 0; font-size: 11px; color: var(--muted); }

.card.busy { opacity: 0.7; }
.card.removed { display: none; }

/* Placeholder card shown while a generation/upload job runs in the background */
.card.placeholder { display: flex; align-items: stretch; }
.placeholder-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}
.placeholder-text { margin: 0; font-size: 12px; color: var(--muted); }
.card.placeholder-error .placeholder-box { border-color: var(--danger); }

.badge {
  align-self: flex-start;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(76, 195, 138, 0.15);
  color: var(--accent-2);
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: white;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 780px) {
  main { grid-template-columns: 1fr; }
  .controls { position: static; }
  #tab-create.tab-panel.active { grid-template-columns: 1fr; }
}

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 32px 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: grid; }
#tab-create.tab-panel.active {
  grid-template-columns: 320px 1fr;
  gap: 20px;
}
#tab-uploaded.tab-panel.active { grid-template-columns: 1fr; gap: 16px; }

.filters {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.filters .field { margin: 0; min-width: 180px; }

/* Uploaded cards: clickable image with play badge */
.card { position: relative; }
.media.clickable { cursor: pointer; }
.play-badge {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s;
}
.play-badge:hover { background: rgba(0,0,0,0.8); }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 0; }
.pager button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.pager button:disabled { opacity: 0.4; cursor: default; }
.pager-label { color: var(--muted); font-size: 13px; }

/* Video modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.75); }
.modal-body {
  position: relative;
  z-index: 1;
  max-width: min(92vw, 460px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.modal-body video { width: 100%; border-radius: 8px; display: block; background: #000; }
.modal-meta { color: var(--muted); font-size: 13px; padding-top: 8px; text-align: center; }
.modal-close {
  position: absolute;
  top: -14px; right: -14px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card h1 { margin: 0; font-size: 22px; }
.login-card .tag { margin: 0; }
.login-error { color: var(--danger); font-size: 13px; margin: 0; min-height: 18px; }

.header-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.logout-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.logout-btn:hover { border-color: var(--accent); }

/* ---------- Styles manager ---------- */
.hidden { display: none !important; }

textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}
textarea:focus { border-color: var(--accent); }

.style-form h2 { margin: 0 0 4px; font-size: 18px; }
.style-form-actions { display: flex; gap: 10px; }
.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.secondary:hover { border-color: var(--accent); }
.undo-btn { color: var(--muted); }
.undo-btn:hover { border-color: var(--accent); color: var(--text); }
.danger { background: #7f1d1d; color: #fee2e2; }
.danger:hover { background: #991b1b; }

.styles-list { display: flex; flex-direction: column; gap: 10px; }
.style-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.style-info { flex: 1; min-width: 0; }
.style-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.style-id {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 7px;
}
.style-desc { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.style-actions { display: flex; gap: 8px; flex-shrink: 0; }
.style-actions button { padding: 8px 14px; font-size: 13px; }
