/* Pace — ultra-minimal, monochrome, Cursor/v0 inspired.
   Design tokens drive both themes; everything else inherits. */

/* ── Tokens ──────────────────────────────────────────────────────────── */
:root {
  --maxw: 720px;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --text: #18181b;
  --text-soft: #52525b;
  --text-faint: #a1a1aa;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --accent: #18181b;
  --accent-soft: #3f3f46;
  --danger: #b91c1c;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --shadow-lift: 0 2px 8px rgba(0,0,0,.06), 0 16px 48px rgba(0,0,0,.08);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --ease: cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
  --bg: #0e0e10;
  --surface: #161618;
  --surface-2: #1d1d20;
  --text: #ededee;
  --text-soft: #a1a1aa;
  --text-faint: #71717a;
  --line: #27272a;
  --line-strong: #3f3f46;
  --accent: #fafafa;
  --accent-soft: #d4d4d8;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --shadow-lift: 0 2px 8px rgba(0,0,0,.35), 0 16px 48px rgba(0,0,0,.4);
}

/* ── Reset / base ────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { font-size: 18px; opacity: .85; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--text-soft);
  font-size: 15px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* key field */
.key-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  transition: border-color .15s var(--ease);
}
.key-field:focus-within { border-color: var(--line-strong); }
.key-label { font-size: 11px; color: var(--text-faint); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
#apiKey {
  width: 150px;
  border: none; outline: none; background: none;
  font-size: 13px; font-family: var(--mono);
}
#apiKey::placeholder { color: var(--text-faint); }
.key-eye { font-size: 16px; color: var(--text-faint); line-height: 1; }
.key-eye:hover { color: var(--text); }

/* ── Stage / composer ────────────────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 64px 24px 48px;
}
.composer { width: 100%; max-width: var(--maxw); }
.composer-title {
  font-size: 30px; font-weight: 600; letter-spacing: -.02em;
  margin-bottom: 6px;
}
.composer-sub { font-size: 15px; color: var(--text-soft); margin-bottom: 28px; }

/* the "smart" input shell */
.input-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input-shell:focus-within {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lift);
}
.script-input {
  width: 100%;
  border: none; outline: none; background: none; resize: vertical;
  padding: 20px 22px 8px;
  font-size: 15px; line-height: 1.6;
  min-height: 92px;
}
.script-input::placeholder { color: var(--text-faint); }

/* chips row */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px 16px;
}

/* ── Dropdown chip ───────────────────────────────────────────────────── */
.chip { position: relative; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px 6px 12px;
  font-size: 13px;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.chip-btn:hover { background: var(--surface); border-color: var(--line-strong); }
.chip-label { color: var(--text-faint); font-size: 12px; }
.chip-value { color: var(--text); font-weight: 500; }
.chip-caret { color: var(--text-faint); font-size: 11px; }

.chip-menu {
  position: absolute;
  top: calc(100% + 6px); left: 0;
  min-width: 180px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  padding: 6px;
  z-index: 50;
  animation: pop .12s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.chip-menu button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px; text-align: left;
  color: var(--text-soft);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.chip-menu button:hover { background: var(--surface-2); color: var(--text); }
.chip-menu button.active { color: var(--text); font-weight: 500; }
.chip-menu button.active::after { content: '✓'; color: var(--text-faint); font-size: 12px; }

/* ── Action row ──────────────────────────────────────────────────────── */
.action-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 20px;
}
.cost {
  font-size: 13px; color: var(--text-faint);
  font-family: var(--mono);
}
.run-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--accent);
  color: var(--bg);
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  transition: opacity .15s var(--ease), transform .08s var(--ease);
}
.run-btn:hover:not(:disabled) { opacity: .9; }
.run-btn:active:not(:disabled) { transform: scale(.98); }
.run-btn:disabled { opacity: .35; cursor: not-allowed; }

.run-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: var(--bg);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress ────────────────────────────────────────────────────────── */
.progress {
  width: 100%; max-width: var(--maxw);
  margin-top: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  animation: fade .3s var(--ease);
}
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.progress-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 14px;
}
.progress-stage { font-size: 14px; font-weight: 500; text-transform: capitalize; }
.progress-pct { font-size: 13px; color: var(--text-faint); font-family: var(--mono); }

.progress-track {
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .35s var(--ease);
}

.progress-stages {
  display: flex; gap: 6px;
  margin-top: 16px;
  font-size: 11px; color: var(--text-faint);
  font-family: var(--mono); text-transform: lowercase;
}
.pstep {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  transition: all .2s var(--ease);
}
.pstep.done { color: var(--text-soft); border-color: var(--line-strong); }
.pstep.done::before { content: '✓ '; }
.pstep.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }

.progress-log {
  margin-top: 14px;
  font-size: 12px; color: var(--text-faint);
  font-family: var(--mono);
  min-height: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Result ──────────────────────────────────────────────────────────── */
.result {
  width: 100%; max-width: var(--maxw);
  margin-top: 40px;
  animation: fade .4s var(--ease);
}
.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}
.player {
  width: 100%; display: block;
  background: #000;
  max-height: 70vh;
}
.result-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}
.result-info { display: flex; flex-direction: column; gap: 3px; }
.result-title { font-size: 14px; font-weight: 500; }
.result-stats { font-size: 12px; color: var(--text-faint); font-family: var(--mono); }

.download-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px; font-weight: 500;
  text-decoration: none; color: var(--text);
  transition: background .15s var(--ease);
}
.download-btn:hover { background: var(--surface); border-color: var(--line-strong); }

.result-yt {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-soft);
}

.again-btn {
  display: block; margin: 20px auto 0;
  font-size: 13px; color: var(--text-soft);
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.again-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-lift);
  z-index: 100;
  max-width: 90vw;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.warning { background: #f59e0b; color: #000; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.footer {
  display: flex; justify-content: space-between;
  padding: 18px 28px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-faint);
  font-family: var(--mono);
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .topbar { padding: 14px 16px; }
  #apiKey { width: 110px; }
  .stage { padding: 40px 16px 32px; }
  .composer-title { font-size: 24px; }
  .footer { padding: 14px 16px; flex-direction: column; gap: 4px; }
  .action-row { flex-direction: column-reverse; gap: 14px; align-items: stretch; }
}

/* ─ Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 200;
  animation: fade .2s var(--ease);
}
.modal-overlay:not([hidden]) {
  display: flex;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px; width: 90%;
  box-shadow: var(--shadow-lift);
}
.modal h3 { margin: 0 0 8px; font-size: 16px; }
.modal-hint { font-size: 12px; color: var(--text-faint); margin: 0 0 16px; }
.modal input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text);
  font-size: 14px; font-family: var(--mono);
  box-sizing: border-box;
}
.modal input:focus { outline: none; border-color: var(--accent); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 16px;
}
.modal-actions button {
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.modal-actions button:last-child {
  background: var(--accent); color: var(--bg); border-color: var(--accent);
}
.modal-actions button:hover { opacity: .9; }

/* ── Welcome modal ─────────────────────────────────────────────────── */
.welcome-modal {
  max-width: 560px;
  padding: 32px;
}
.welcome-modal h2 {
  margin: 0 0 12px;
  font-size: 22px;
}
.welcome-text {
  font-size: 14px;
  color: var(--text-soft);
  margin: 0 0 24px;
}
.welcome-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}
.step {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.step-content {
  flex: 1;
}
.step-content strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}
.step-content p {
  margin: 0;
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.5;
}
.step-content a {
  color: var(--accent);
  text-decoration: none;
}
.step-content a:hover {
  text-decoration: underline;
}
.welcome-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s var(--ease);
}
.welcome-btn:hover {
  opacity: .9;
}

/* ── Settings modal ────────────────────────────────────────────────── */
.settings-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}
.settings-section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.settings-section h4 {
  margin: 0 0 8px;
  font-size: 15px;
}
.settings-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0 0 16px;
}
.channels-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.channel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.channel-item button {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-soft);
  font-size: 12px;
  cursor: pointer;
}
.channel-item button:hover {
  color: var(--danger);
  border-color: var(--danger);
}
.settings-btn {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.settings-btn:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

/* ── Voice descriptions ──────────────────────────────────────────────── */
.voice-item {
  display: flex; flex-direction: column; gap: 2px;
}
.voice-name { font-weight: 500; }
.voice-desc { font-size: 11px; color: var(--text-faint); }

/* ── Custom input for chips ──────────────────────────────────────────── */
.chip-custom-input {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  z-index: 51;
  box-shadow: var(--shadow-lift);
}
.chip-custom-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Model options dropdown items ────────────────────────────────────── */
.model-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: 100%;
}
.model-name { font-weight: 500; }
.model-rate {
  font-size: 10px; color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 4px;
  font-family: var(--mono);
}
