:root {
  --bg: #0a0a0e;
  --card: rgba(255,255,255,0.045);
  --card-border: rgba(255,255,255,0.07);
  --card-solid: #16151c;
  --text: #f3f1f6;
  --text-dim: #8d8a97;
  --text-faint: #5e5c66;
  --accent: #b7a6ff;
  --accent-2: #8f7bff;
  --accent-soft: rgba(183,166,255,0.14);
  --danger: #ff8a8a;
  --success: #8fe3b0;
  --warn: #f0c77e;
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background:
    radial-gradient(circle at 18% 0%, rgba(143,123,255,0.16), transparent 42%),
    radial-gradient(circle at 85% 18%, rgba(100,90,220,0.10), transparent 40%),
    var(--bg);
}

button { font-family: inherit; cursor: pointer; }

/* ---------------- Topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 6px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.balance-chip {
  background: var(--card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

main#main {
  flex: 1;
  overflow-y: auto;
  padding: 6px 20px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- Bottom nav: icon+label, no box ---------------- */

.bottomnav {
  display: flex;
  flex-shrink: 0;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  gap: 4px;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.2s;
}

.nav-btn.active { color: var(--accent); }

.nav-icon {
  font-size: 18px;
  line-height: 1;
}

/* ---------------- Section labels ---------------- */

.section-label {
  font-size: 11px;
  color: var(--text-faint);
  margin: 22px 2px 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.section-label:first-child { margin-top: 2px; }

/* ---------------- Glass card ---------------- */

.card {
  background: var(--card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

textarea.field {
  width: 100%;
  background: var(--card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 16px;
  font-size: 15px;
  min-height: 84px;
  resize: none;
  font-family: inherit;
}
textarea.field::placeholder { color: var(--text-faint); }
textarea.field:focus { outline: none; border-color: var(--accent); }

input.field {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  color: var(--text);
  padding: 13px 18px;
  font-size: 15px;
  font-family: inherit;
}
input.field::placeholder { color: var(--text-faint); }
input.field:focus { outline: none; border-color: var(--accent); }

/* ---------------- Segmented control (provider) ---------------- */

.segmented {
  display: flex;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
}

.segmented .seg {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: none;
}

.segmented .seg.selected {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------------- Compact chip selectors (resolution / aspect / duration) ---------------- */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.chip.selected {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
  font-weight: 700;
}

/* ---------------- Character avatars row ---------------- */

.char-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 2px 2px 6px;
}

.char-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  width: 58px;
}

.char-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  background: var(--card-solid);
}

.char-avatar-wrap.selected .char-avatar {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.char-avatar-add {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1.5px dashed var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-faint);
}

.char-name {
  font-size: 10.5px;
  color: var(--text-faint);
  text-align: center;
  max-width: 58px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.char-avatar-wrap.selected .char-name { color: var(--text-dim); }

/* ---------------- Motion-reference card (collapsed, compact) ---------------- */

.motion-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
}

.motion-card .m-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.motion-card .m-icon video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }

.motion-card .m-text { flex: 1; min-width: 0; }
.motion-card .m-title { font-size: 13.5px; font-weight: 600; }
.motion-card .m-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }

.motion-card .m-remove {
  background: none; border: none; color: var(--text-faint); font-size: 16px;
}

/* ---------------- Slider ---------------- */

.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 12px 0 0;
}

/* ---------------- Buttons ---------------- */

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #14121f;
  border: none;
  border-radius: var(--radius-pill);
  padding: 17px;
  font-size: 15.5px;
  font-weight: 700;
  margin-top: 24px;
  box-shadow: 0 8px 24px -8px rgba(143,123,255,0.5);
}
.btn-primary:disabled { opacity: 0.45; box-shadow: none; }

.btn-secondary {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 14px;
  font-size: 14.5px;
  font-weight: 600;
  margin-top: 10px;
}

.hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 10px;
  line-height: 1.45;
  padding: 0 2px;
}
.hint.warn { color: var(--warn); }

/* ================= HOME SCREEN ================= */

.orb-wrap {
  display: flex;
  justify-content: center;
  padding: 18px 0 6px;
}

.orb {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background: radial-gradient(circle at 32% 28%, rgba(183,166,255,0.5), rgba(143,123,255,0.08) 60%, transparent 70%),
              var(--card-solid);
  border: 1px solid var(--card-border);
  box-shadow: 0 0 60px -10px rgba(143,123,255,0.35), inset 0 0 40px rgba(183,166,255,0.08);
}

.orb .orb-amount {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.orb .orb-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.pill-badge {
  display: block;
  margin: 16px auto 0;
  width: fit-content;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 7px 18px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}

.stat-strip {
  display: flex;
  gap: 10px;
  margin-top: 26px;
}

.stat-pill {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  text-align: center;
}
.stat-pill .num { font-size: 20px; font-weight: 700; }
.stat-pill .lbl { font-size: 10.5px; color: var(--text-faint); margin-top: 3px; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}

.action-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  color: var(--text);
}
.action-card .a-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  margin-bottom: 10px;
}
.action-card .a-title { font-size: 13.5px; font-weight: 600; }
.action-card .a-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* ================= HISTORY ================= */

.history-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
}

.history-thumb {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--card-solid);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  overflow: hidden;
}
.history-thumb video { width: 100%; height: 100%; object-fit: cover; }

.history-body { flex: 1; min-width: 0; }
.history-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.history-meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.history-prompt {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.status-completed .status-dot { background: var(--success); }
.status-processing .status-dot { background: var(--warn); }
.status-failed .status-dot { background: var(--danger); }
.status-pending .status-dot { background: var(--text-faint); }

/* ================= CHARACTERS ================= */

.char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.char-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 10px;
  text-align: center;
  position: relative;
}
.char-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
}
.char-card .name {
  font-size: 11.5px;
  margin-top: 7px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.char-card .del {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(10,10,14,0.7);
  backdrop-filter: blur(6px);
  color: #fff;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  border: none;
}

.char-card-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px dashed var(--card-border);
  border-radius: var(--radius-md);
  aspect-ratio: 0.82;
  color: var(--text-faint);
  font-size: 12px;
  background: none;
}

/* ================= Modal ================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5,5,8,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}

.modal-sheet {
  background: var(--card-solid);
  border: 1px solid var(--card-border);
  border-bottom: none;
  border-radius: 28px 28px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.file-preview {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  background: var(--card);
  object-fit: cover;
  flex-shrink: 0;
}

.file-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  border-radius: var(--radius-pill);
  padding: 11px 16px;
  font-size: 13px;
  flex: 1;
  text-align: left;
}

/* ================= Toast ================= */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(16px);
  background: var(--card-solid);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 13px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 100;
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 12px 30px -8px rgba(0,0,0,0.5);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================= Spinner ================= */

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(20,18,31,0.3);
  border-top-color: #14121f;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 13.5px;
  line-height: 1.6;
}
