:root {
  --bg: #06070A;
  --surface-1: #0B0D12;
  --surface-2: #11141B;
  --surface-3: #181C25;
  --border: rgba(255,255,255,0.08);
  --accent: #00ff88;
  --accent-dim: rgba(0,255,136,0.15);
  --warn: #FFB020;
  --danger: #FF5A5F;
  --text: #F5F7FB;
  --text-muted: #97A3B6;
  --radius: 14px;
  --radius-sm: 9px;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Space Grotesk', sans-serif; }

/* ---------- Login ---------- */
.login-gate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #0c1119, var(--bg));
}
.login-card {
  width: 320px; padding: 32px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { margin: 0; font-size: 26px; }
.login-logo span { color: var(--accent); }
.login-sub { margin: 0 0 8px; color: var(--text-muted); font-size: 12px; }
.login-card input {
  width: 100%; padding: 12px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-error { margin: 0; color: var(--danger); font-size: 12px; }

/* ---------- Layout ---------- */
.app { max-width: 1440px; margin: 0 auto; padding: 0 24px 48px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 4px; margin-bottom: 8px;
}
.brand { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 20px; }
.brand span { color: var(--accent); }
.api-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.api-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.api-status[data-state="overdue"] .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.api-status[data-state="overdue"] #apiStatusText::after { content: ' (overdue)'; color: var(--warn); }

.studio {
  display: grid; grid-template-columns: 440px 1fr; gap: 24px;
  align-items: start;
}
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
}

/* ---------- Composer ---------- */
.mode-toggle {
  display: flex; gap: 4px; background: var(--surface-2);
  padding: 4px; border-radius: var(--radius-sm); margin-bottom: 18px;
}
.mode-toggle button {
  flex: 1; padding: 9px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-muted);
  font-weight: 600; font-size: 13px; cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.mode-toggle button.active { background: var(--accent); color: #06070A; }

.field-label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
  margin: 0 0 6px; text-transform: uppercase; letter-spacing: .03em;
}
textarea, select {
  width: 100%; padding: 11px 13px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 14px; resize: vertical;
}
textarea:focus, select:focus { outline: none; border-color: var(--accent); }
select {
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2397A3B6' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0; }

/* references */
.refs-head { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; margin: 18px 0 8px; }
.refs-head span { display: block; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 11px; opacity: .8; margin-top: 2px; }
.refs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.refs-2 { grid-template-columns: 1fr 1fr; }

/* multiple reference images */
.ref-images { display: flex; flex-wrap: wrap; gap: 10px; }
.ref-thumb { position: relative; width: 88px; height: 88px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.ref-add {
  width: 88px; height: 88px; border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-muted); cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: border-color .15s;
}
.ref-add:hover { border-color: var(--accent); }
.ref-add span { font-size: 24px; color: var(--accent); line-height: 1; }
.ref-add small { font-size: 10px; }

.audio-toggle { display: flex; align-items: center; gap: 9px; margin: 16px 0 4px; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; }
.audio-toggle input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.ref-slot {
  position: relative; border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer; min-height: 104px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; transition: border-color .15s, background .15s;
}
.ref-slot.dragover { border-color: var(--accent); background: var(--accent-dim); }
.ref-empty { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--text-muted); padding: 10px; text-align: center; }
.ref-ico { font-size: 22px; }
.ref-empty span { font-size: 12px; font-weight: 600; }
.ref-empty small { font-size: 10px; opacity: .7; }
.ref-filled { position: relative; width: 100%; height: 100%; }
.ref-filled img, .ref-filled video { width: 100%; height: 104px; object-fit: cover; display: block; background: #000; }
.ref-clear {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.65); color: #fff; font-size: 15px; cursor: pointer; line-height: 1;
}
@media (max-width: 560px) { .refs { grid-template-columns: 1fr; } }

.i2v-block { margin: 16px 0; }
.drop-zone {
  position: relative; border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer; min-height: 130px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  transition: border-color .15s, background .15s;
}
.drop-zone.dragover { border-color: var(--accent); background: var(--accent-dim); }
.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-muted); padding: 20px; text-align: center; }
.drop-plus { font-size: 28px; color: var(--accent); line-height: 1; }
.drop-empty small { font-size: 11px; opacity: .7; }
.drop-filled { position: relative; width: 100%; }
.drop-filled img { width: 100%; max-height: 220px; object-fit: contain; display: block; }
.img-clear {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  border: none; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff;
  font-size: 18px; cursor: pointer; line-height: 1;
}

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 18px; min-height: 44px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #06070A; font-weight: 700; font-size: 14px;
  cursor: pointer; text-decoration: none; font-family: inherit; transition: filter .15s, opacity .15s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-generate { width: 100%; margin-top: 4px; }
.btn-ghost {
  padding: 10px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-ghost:hover { border-color: var(--accent); }
.btn-text { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; font-family: inherit; }
.cost-hint { margin: 12px 0 0; font-size: 11px; color: var(--text-muted); line-height: 1.5; }

/* ---------- Stage ---------- */
.stage { min-height: 420px; display: flex; align-items: center; justify-content: center; }
.pane { display: none; flex-direction: column; align-items: center; gap: 14px; width: 100%; text-align: center; color: var(--text-muted); }
.stage[data-state="idle"]    .pane-idle,
.stage[data-state="loading"] .pane-loading,
.stage[data-state="result"]  .pane-result,
.stage[data-state="error"]   .pane-error { display: flex; }
.idle-art { font-size: 44px; color: var(--surface-3); }

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

.pane-result { gap: 12px; }
#resultVideo { width: 100%; max-height: 460px; border-radius: var(--radius-sm); background: #000; }
.result-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }
.result-meta { font-size: 12px; color: var(--text-muted); }
.result-warn { font-size: 11px; color: var(--warn); margin: 0; }

.error-icon {
  width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(255,90,95,.15); color: var(--danger); font-size: 24px; font-weight: 700;
}
.pane-error[data-kind="overdue"] .error-icon { background: rgba(255,176,32,.15); color: var(--warn); }
.pane-error h3 { margin: 0; color: var(--text); }
.pane-error p { margin: 0; max-width: 360px; line-height: 1.5; }

/* ---------- Recent ---------- */
.recent { margin-top: 28px; }
.recent-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.recent-head h2 { margin: 0; font-size: 15px; color: var(--text-muted); }
.recent-strip { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.recent-card {
  flex: 0 0 168px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; cursor: pointer; position: relative;
}
.recent-card video { width: 100%; height: 96px; object-fit: cover; background: #000; display: block; }
.recent-card .rc-meta { padding: 8px 10px; font-size: 11px; color: var(--text-muted); }
.rc-placeholder { width: 100%; height: 96px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--text-muted); font-size: 11px; text-transform: capitalize; }
.gen-muted { color: var(--text-muted); font-size: 13px; padding: 8px 2px; }
.recent-card .rc-del {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 14px; line-height: 1;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: var(--radius-sm); font-size: 13px; z-index: 60;
}

@media (max-width: 960px) {
  .studio { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
