:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --border: #e3e0d8;
  --border-strong: #cfcbc0;
  --text: #1c1b18;
  --text-2: #5f5b52;
  --text-3: #8c877b;
  --accent: #d9480f;
  --accent-hover: #c03f0c;
  --accent-soft: #fdeee6;
  --accent-text: #ffffff;
  --good: #2b8a3e;
  --good-soft: #e6f4ea;
  --warn: #b35c00;
  --warn-soft: #fff1dc;
  --bad: #c92a2a;
  --bad-soft: #fdeaea;
  --info: #1864ab;
  --info-soft: #e7f0fb;
  --shadow: 0 1px 2px rgba(28, 27, 24, 0.06), 0 4px 16px rgba(28, 27, 24, 0.05);
  --radius: 10px;
  --font: 'Be Vietnam Pro', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1c1c19;
    --surface-2: #252521;
    --border: #2f2e2a;
    --border-strong: #45433d;
    --text: #edebe6;
    --text-2: #b0aca2;
    --text-3: #807c72;
    --accent: #ff7a3d;
    --accent-hover: #ff8f5c;
    --accent-soft: #3a2116;
    --accent-text: #1a0d06;
    --good: #69db7c;
    --good-soft: #17301d;
    --warn: #ffb547;
    --warn-soft: #36280f;
    --bad: #ff8787;
    --bad-soft: #3a1a1a;
    --info: #74c0fc;
    --info-soft: #132a3d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
svg { width: 1em; height: 1em; fill: currentColor; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 24px; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 0.86em; font-variant-ligatures: none; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a {
  text-decoration: none; color: var(--text-2); font-weight: 500;
  padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

/* Layout */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 80px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-body { padding: 16px; }

/* Controls */
button, .btn {
  font: inherit; font-weight: 500; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: var(--bad); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 50%; }
.icon-btn svg { width: 15px; height: 15px; }
.play { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.play:hover { background: var(--accent); color: var(--accent-text); }
.play.playing { background: var(--accent); color: var(--accent-text); }

label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=password], select, textarea {
  font: inherit; width: 100%; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; line-height: 1.65; }
.script-editor { min-height: 460px; font-size: 15px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.field { margin-bottom: 16px; }
.field .hint { margin-top: 4px; font-size: 12.5px; color: var(--text-3); }
.fields-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.inline-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 0; }

/* Pills & badges */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12.5px; font-weight: 500;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.pill.no-dot::before { display: none; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.spin::before { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.2; } }

/* Projects list */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.project-card { display: block; padding: 16px; text-decoration: none; transition: border-color 0.12s, transform 0.12s; }
.project-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.project-card h2 { margin-bottom: 10px; }
.project-card .meta { display: flex; gap: 14px; color: var(--text-2); font-size: 13px; flex-wrap: wrap; }
.empty { text-align: center; padding: 56px 24px; }
.empty h2 { margin-bottom: 6px; }
.empty p { margin-bottom: 18px; }

/* Project view */
.title-input {
  font: 600 24px/1.25 var(--font); letter-spacing: -0.01em; border: 1px solid transparent; background: transparent;
  padding: 2px 6px; margin-left: -7px; border-radius: 6px; width: min(100%, 560px);
}
.title-input:hover { border-color: var(--border); }
.player-bar { display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin-bottom: 20px; flex-wrap: wrap; }
.player-bar .stats { display: flex; gap: 22px; flex-wrap: wrap; }
.stat .k { font-size: 12px; color: var(--text-3); }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.player-bar audio { flex: 1; min-width: 240px; height: 36px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; flex: 1; min-width: 160px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.3s; }
.overrides { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.overrides .field { margin: 0; }
.overrides select, .overrides input { height: 34px; padding: 4px 8px; }

.clips { list-style: none; margin: 0; padding: 0; }
.clip {
  display: grid; grid-template-columns: 16px 20px 32px minmax(0, 1fr) auto; gap: 10px; align-items: start;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.clip:last-child { border-bottom: 0; }
.clip.para-end { border-bottom: 2px solid var(--border-strong); }
.clip .num { font: 500 12px var(--mono); color: var(--text-3); padding-top: 8px; text-align: right; }
.clip .body { min-width: 0; }
.clip .body.editing { grid-column: span 3; }
.clip .text { padding-top: 5px; overflow-wrap: anywhere; }
.clip .spoken { font-size: 12.5px; color: var(--info); margin-top: 3px; }
.clip .facts { display: flex; gap: 8px; margin-top: 6px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--text-3); }
.clip .err { color: var(--bad); font-size: 12.5px; margin-top: 4px; }
.clip .actions { display: flex; gap: 2px; align-items: center; padding-top: 1px; }
.clip textarea { min-height: 70px; margin-top: 2px; }
.clip.selected { background: var(--accent-soft); }
.clip input[type=checkbox] { margin-top: 10px; accent-color: var(--accent); }
.clip-placeholder { width: 32px; height: 32px; border-radius: 50%; border: 1px dashed var(--border-strong); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td input[type=text] { min-width: 160px; }

.tabs { display: flex; gap: 4px; }
.tabs button { height: 30px; font-size: 13px; }
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.audition-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 14px; }
.audition-results .card { padding: 12px; }
.audition-results audio { width: 100%; height: 34px; margin-top: 8px; }

pre.snippet {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; font: 12.5px/1.55 var(--mono); margin: 8px 0 0;
  font-variant-ligatures: none; white-space: pre;
}

/* Dialog */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(20, 18, 14, 0.45); }
dialog form { padding: 22px; }
dialog h2 { margin-bottom: 16px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 40px); }
.toast {
  padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow); font-size: 14px; max-width: 420px; animation: slide 0.18s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .brand { font-size: 0; gap: 0; }
  .brand svg { font-size: 15px; }
  .page { padding: 20px 16px 64px; }
  .clip { grid-template-columns: 32px minmax(0, 1fr); }
  .clip .num, .clip input[type=checkbox], .clip .edit-spacer { display: none; }
  .clip .actions { grid-column: 2; }
  .clip .body.editing { grid-column: 1 / -1; }
  #status { display: none; }
}
