:root {
  --bg: #0b0e13;
  --panel: #121620;
  --panel-2: #1a1f2b;
  --border: #242b3a;
  --text: #e8eef6;
  --muted: #8893a6;
  /* SilverSea brand blue */
  --accent: #1f7ac0;
  --accent-2: #3fa3dd;
  --ok: #34d399;
  --err: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #143049 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; border-bottom: 1px solid var(--border);
}
.brandwrap { display: flex; align-items: center; gap: 12px; }
.logo {
  height: 48px; width: auto; background: #fff; padding: 5px 10px;
  border-radius: 9px; display: block;
}
.brand { font-weight: 700; font-size: 19px; letter-spacing: .3px; color: var(--accent-2); }
.subtitle { color: var(--muted); font-size: 13px; font-weight: 500; }

.topbar-right { display: flex; align-items: center; gap: 16px; }
.credits {
  font-size: 12px; color: var(--accent-2); border: 1px solid var(--border);
  background: var(--panel-2); padding: 6px 12px; border-radius: 20px; white-space: nowrap;
}
.credits:empty { display: none; }

/* tabs */
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel-2); border-color: var(--border); color: var(--accent-2); }

.layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px;
  max-width: 1200px; margin: 28px auto; padding: 0 24px;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
}
.preview-panel { position: sticky; top: 24px; align-self: start; }

.step { margin-bottom: 26px; }
h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }
.num {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 12px; font-weight: 700; color: #fff;
}

/* avatars */
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.avatar-card {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  border: 2px solid transparent; cursor: pointer; background: var(--panel-2);
}
.avatar-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-card .no-img {
  width: 100%; height: 100%; display: grid; place-items: center; padding: 8px;
  text-align: center; font-size: 12px; color: var(--muted);
}
.avatar-card .label {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 4px 6px;
  font-size: 11px; background: linear-gradient(transparent, rgba(0,0,0,.8)); color: #fff;
}
.avatar-card.selected { border-color: var(--accent); }
.avatar-card.selected::after {
  content: "✓"; position: absolute; top: 5px; right: 6px; font-size: 12px;
  background: var(--accent); width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
}

.upload-tile {
  margin-top: 12px; display: flex; align-items: center; gap: 10px;
  border: 1px dashed var(--border); border-radius: 12px; padding: 12px 14px;
  cursor: pointer; color: var(--muted); font-size: 13px; transition: border-color .15s;
}
.upload-tile:hover { border-color: var(--accent); color: var(--text); }
.upload-tile .plus { font-size: 18px; }

/* voices */
.voice-list { display: flex; flex-direction: column; gap: 10px; }
.voice-row {
  display: flex; align-items: center; gap: 12px;
  border: 2px solid transparent; background: var(--panel-2);
  border-radius: 12px; padding: 12px 14px; cursor: pointer;
}
.voice-row.selected { border-color: var(--accent); }
.voice-row .play {
  width: 32px; height: 32px; flex: none; border-radius: 50%; border: none;
  background: var(--border); color: var(--text); cursor: pointer; font-size: 13px;
}
.voice-row .play:disabled { opacity: .4; cursor: not-allowed; }
.voice-row .play.playing { background: var(--accent); color: #fff; }
.voice-name { font-size: 14px; }

/* script */
textarea {
  width: 100%; resize: vertical; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-size: 14px;
  font-family: inherit; line-height: 1.5;
}
textarea:focus { outline: none; border-color: var(--accent); }
.counter { text-align: right; color: var(--muted); font-size: 12px; margin-top: 6px; }

.model-select {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.model-select:focus { outline: none; border-color: var(--accent); }
.model-select option:disabled { color: var(--muted); }

.generate {
  width: 100%; padding: 14px; border: none; border-radius: 12px; cursor: pointer;
  font-size: 15px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.generate:disabled { opacity: .45; cursor: not-allowed; }

.download {
  width: 100%; margin-top: 16px; padding: 13px; border: 1px solid var(--accent);
  border-radius: 12px; cursor: pointer; font-size: 14px; font-weight: 600;
  background: rgba(31,122,192,.14); color: var(--accent-2);
}

/* preview */
.preview-area {
  min-height: 280px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 12px; display: grid; place-items: center; overflow: hidden; position: relative;
}
.placeholder { color: var(--muted); font-size: 14px; padding: 20px; text-align: center; }
/* Let the video keep its own aspect ratio so the whole frame is always visible
   (no cropping), and stay clickable for the native play/scrub controls. */
.preview-area video {
  display: block; width: 100%; height: auto; max-height: 70vh;
  object-fit: contain; background: #000; border-radius: 12px; position: relative; z-index: 1;
}
.progress { text-align: center; }
.progress p { margin: 6px 0 0; font-size: 14px; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* history */
.history-wrap { max-width: 1100px; margin: 28px auto; padding: 0 24px; }
.history-title { font-size: 18px; margin: 0 0 18px; }
.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.history-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.history-card .vid { aspect-ratio: 16/9; background: #000; display: grid; place-items: center; }
.history-card .vid video { width: 100%; height: 100%; object-fit: contain; }
.history-card .vid .pending { color: var(--muted); font-size: 13px; text-align: center; padding: 16px; }
.history-card .meta { padding: 14px; }
.history-card .meta .who { font-size: 14px; font-weight: 600; }
.history-card .meta .when { color: var(--muted); font-size: 12px; margin: 3px 0 8px; }
.history-card .meta .script { color: var(--muted); font-size: 12px; line-height: 1.4; }
.history-card .meta .actions { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.history-card .meta .dl {
  display: inline-block; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--accent); background: rgba(31,122,192,.14); color: var(--accent-2);
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.history-card .meta .dl[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.history-card .meta .del,
.history-card .meta .rename {
  padding: 8px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer;
}
.history-card .meta .rename:hover { color: var(--accent-2); border-color: var(--accent); }
.history-card .meta .del:hover { color: var(--err); border-color: var(--err); }
.badge { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--panel-2); color: var(--accent-2); border: 1px solid var(--border); }

.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }
.error { color: var(--err); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.hidden { display: none !important; }
