:root {
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #f0f0f7;
  --border: #e3e3ee;
  --text: #17172b;
  --muted: #6b6b85;
  --accent: #6d5efc;
  --accent-2: #8f7dff;
  --accent-soft: #ecebff;
  --on-accent: #ffffff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --ok: #1f9d63;
  --ok-soft: #e4f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --shadow: 0 1px 2px rgba(20, 20, 50, .05), 0 8px 24px rgba(20, 20, 50, .06);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f17;
    --surface: #171724;
    --surface-2: #1f1f2f;
    --border: #2b2b3e;
    --text: #ececf6;
    --muted: #9a9ab3;
    --accent: #8b7dff;
    --accent-2: #a597ff;
    --accent-soft: #252244;
    --on-accent: #ffffff;
    --danger: #ff6369;
    --danger-soft: #3a1d22;
    --ok: #3dd68c;
    --ok-soft: #15301f;
    --warn: #f5b74f;
    --warn-soft: #3a2c13;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f0f17;
  --surface: #171724;
  --surface-2: #1f1f2f;
  --border: #2b2b3e;
  --text: #ececf6;
  --muted: #9a9ab3;
  --accent: #8b7dff;
  --accent-2: #a597ff;
  --accent-soft: #252244;
  --on-accent: #ffffff;
  --danger: #ff6369;
  --danger-soft: #3a1d22;
  --ok: #3dd68c;
  --ok-soft: #15301f;
  --warn: #f5b74f;
  --warn-soft: #3a2c13;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 26px; letter-spacing: -.02em; }
h2 { font-size: 20px; letter-spacing: -.01em; }
h3 { font-size: 16px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ── Boot / logo ─────────────────────────────── */
.boot { min-height: 100vh; display: grid; place-items: center; }
.logo-mark { display: inline-flex; align-items: center; gap: 3px; height: 28px; }
.logo-mark span { width: 4px; border-radius: 4px; background: var(--accent); animation: bar 1.1s ease-in-out infinite; }
.logo-mark span:nth-child(1) { height: 40%; animation-delay: -.3s; }
.logo-mark span:nth-child(2) { height: 80%; animation-delay: -.15s; }
.logo-mark span:nth-child(3) { height: 100%; }
.logo-mark span:nth-child(4) { height: 60%; animation-delay: -.45s; }
.logo-mark.static span { animation: none; }
@keyframes bar { 0%, 100% { transform: scaleY(.55); } 50% { transform: scaleY(1); } }

/* ── Layout ──────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, .container { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; text-decoration: none; color: var(--text); }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500;
}
.nav button:hover { color: var(--text); background: var(--surface-2); }
.nav button.active { color: var(--accent); background: var(--accent-soft); }
.topbar .spacer { flex: 1; }
.usage-pill { font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 5px 10px; border-radius: 99px; white-space: nowrap; }
.container { padding-top: 24px; padding-bottom: 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }

.bottom-nav { display: none; }

@media (max-width: 760px) {
  .nav, .usage-pill { display: none; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav button {
    flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 10px; color: var(--muted);
    font-size: 12px; font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  }
  .bottom-nav button.active { color: var(--accent); }
  .bottom-nav svg { width: 22px; height: 22px; }
  .container { padding-bottom: 96px; }
  h1 { font-size: 22px; }
}

/* ── Cards / grid ────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
@media (max-width: 860px) { .grid.cols-2 { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 8px; }

/* ── Forms ───────────────────────────────────── */
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; min-width: 0; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; min-width: 0;
}
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.counter { font-size: 12.5px; color: var(--muted); text-align: right; }
.counter.over { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; flex: none; }

.seg { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 11px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 14px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

details.advanced summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500; list-style: none; }
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::before { content: "▸ "; }
details.advanced[open] summary::before { content: "▾ "; }
details.advanced > .fields { margin-top: 12px; }

/* ── Auth ────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 420px; }
.auth .brand { justify-content: center; margin-bottom: 18px; font-size: 20px; }
.auth h1 { text-align: center; margin-bottom: 6px; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth .seg { width: 100%; margin-bottom: 18px; }
.auth .seg button { flex: 1; }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.features div { text-align: center; font-size: 12.5px; color: var(--muted); }
.features b { display: block; color: var(--text); font-size: 13.5px; margin-bottom: 2px; }

/* ── Voices ──────────────────────────────────── */
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.voice-card { display: flex; flex-direction: column; gap: 12px; }
.voice-card .head { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 17px;
}
.voice-card .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-card .meta { color: var(--muted); font-size: 13px; }
.voice-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 40px 16px; }
.empty .icon { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.empty .icon svg { width: 28px; height: 28px; }
.empty p { margin: 6px auto 16px; max-width: 380px; }

.voice-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; max-height: 260px; overflow: auto; padding: 2px; }
.voice-pick button {
  display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 8px 10px; cursor: pointer; min-width: 0;
}
.voice-pick button:hover { border-color: var(--accent-2); }
.voice-pick button.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.voice-pick .avatar { width: 32px; height: 32px; font-size: 14px; border-radius: 9px; }
.voice-pick .t { min-width: 0; }
.voice-pick .t b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-pick .t span { font-size: 12px; color: var(--muted); }

/* ── Recorder ────────────────────────────────── */
.recorder { border: 1px dashed var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--surface-2); }
.recorder .script { background: var(--surface); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; line-height: 1.6; border: 1px solid var(--border); }
.rec-btn { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; cursor: pointer; display: grid; place-items: center; flex: none; box-shadow: 0 4px 16px rgba(229,72,77,.35); }
.rec-btn svg { width: 26px; height: 26px; }
.rec-btn.recording { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(229,72,77,.5); } 50% { box-shadow: 0 0 0 12px rgba(229,72,77,0); } }
.rec-time { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 650; }
.meter { flex: 1; height: 8px; background: var(--surface); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); min-width: 80px; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--accent)); transition: width .08s; }
.dropzone { border: 1px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer; background: var(--surface-2); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
audio { width: 100%; height: 40px; }

/* ── Jobs / history ──────────────────────────── */
.job { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.job .text { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 99px; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.history-list { display: flex; flex-direction: column; gap: 10px; }

/* ── Modal ───────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(10, 10, 25, .45); z-index: 50; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); padding: 22px; }
.modal .modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 600px) {
  .modal-back { align-items: end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
}

.type-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 600px) { .type-cards { grid-template-columns: 1fr; } }
.type-cards button { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 12px; text-align: left; cursor: pointer; }
.type-cards button b { display: block; font-size: 14px; margin-bottom: 2px; }
.type-cards button span { font-size: 12.5px; color: var(--muted); }
.type-cards button.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.preset-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-height: 280px; overflow: auto; padding: 2px; }
.preset-list button { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 10px; text-align: left; cursor: pointer; }
.preset-list button b { display: block; font-size: 14px; }
.preset-list button span { font-size: 12px; color: var(--muted); }
.preset-list button.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.sample { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.chips button:hover { color: var(--text); border-color: var(--accent-2); }

.notice { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

table.models { width: 100%; border-collapse: collapse; font-size: 14px; }
table.models th, table.models td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.models th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table-wrap { overflow-x: auto; }

/* ── Toasts ──────────────────────────────────── */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 11px 14px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: fade .2s; pointer-events: auto; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 220px; z-index: 30; }
.menu-pop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop .who { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; }
