:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e2e0db;
  --text: #1c1b19;
  --muted: #6b6862;
  --accent: #2563eb;
  --accent-soft: #e6eefc;
  --ok: #15803d;
  --ok-soft: #e5f4ea;
  --warn: #b45309;
  --err: #b91c1c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --surface: #1c1b1a;
    --surface-2: #252422;
    --border: #33312e;
    --text: #ecebe8;
    --muted: #9c988f;
    --accent: #60a5fa;
    --accent-soft: #172338;
    --ok: #4ade80;
    --ok-soft: #14291b;
    --warn: #fbbf24;
    --err: #f87171;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
a:hover { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.error { color: var(--err); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
  margin-bottom: 16px;
}
.grid > .card { margin-bottom: 0; }

/* banners */
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.banner.warn { border-color: var(--warn); }
.banner.info { border-color: var(--accent); }
#jobbar { display: none; }
#jobbar.show { display: block; }
.spinner {
  display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px;
  border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width 0.6s; }

/* forms */
form.inline { display: inline; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.fields { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.fields .grow { flex: 1; min-width: 220px; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-width: 0;
}
input[type="checkbox"] { width: 16px; height: 16px; }
input[type="range"] { padding: 0; }
textarea { width: 100%; min-height: 120px; }
textarea.script { min-height: 340px; font-size: 0.95rem; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button, .btn {
  font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); color: #fff; }
button.small, .btn.small { padding: 3px 9px; font-size: 0.82rem; }
button.ghost { border-color: transparent; background: transparent; }
button.danger:hover { border-color: var(--err); color: var(--err); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
label.check { display: flex; gap: 8px; align-items: center; cursor: pointer; font-size: 0.9rem; color: var(--text); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }

/* projects */
.plist { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.pcard { display: block; text-decoration: none; }
.pcard:hover { border-color: var(--accent); color: inherit; }
.pcard .title { font-weight: 600; margin-bottom: 4px; }

/* steps on the project page */
.steps { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-bottom: 16px; }
.step { display: flex; flex-direction: column; gap: 6px; }
.step .num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; background: var(--surface-2); }
.step.done .num { background: var(--ok-soft); color: var(--ok); }
.step.current .num { background: var(--accent); color: #fff; }
.step .head { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.step .cost { font-size: 0.85rem; color: var(--muted); }
.step form { margin-top: auto; }

/* voice picker */
.voices { max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.voice { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.voice:last-child { border-bottom: none; }
.voice .info { flex: 1; min-width: 0; }
.voice .name { font-weight: 600; }
.voice.chosen { background: var(--accent-soft); }
.current-voice { padding: 8px 12px; border-radius: 8px; background: var(--surface-2); margin-bottom: 10px; }

/* review page */
.chunk { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.chunk:last-child { border-bottom: none; }
.chunk .idx { font-weight: 700; color: var(--muted); padding-top: 2px; }
.chunk .text { cursor: text; border-radius: 6px; padding: 2px 4px; margin: -2px -4px; }
.chunk .text:hover { background: var(--surface-2); }
.chunk .meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chunk .pics { display: flex; gap: 8px; align-items: center; }
.pic { position: relative; width: 200px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: pointer; border: 2px solid transparent; }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic:hover { border-color: var(--accent); }
.pic .badge { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: 0.7rem; padding: 0 5px; border-radius: 4px; }
.pic.empty { display: grid; place-items: center; color: var(--muted); font-size: 0.8rem; }
.arrow { font-size: 1.4rem; color: var(--muted); }
.chooser { grid-column: 2 / 4; background: var(--surface-2); border-radius: 8px; padding: 10px; }
.chooser .cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.cand { position: relative; aspect-ratio: 16/9; border-radius: 6px; overflow: hidden; cursor: pointer; border: 3px solid transparent; background: var(--surface); }
.cand img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cand.chosen { border-color: var(--accent); }
.cand .badge { position: absolute; left: 3px; bottom: 3px; background: rgba(0,0,0,.65); color: #fff; font-size: 0.68rem; padding: 0 4px; border-radius: 4px; }
.cand a.src { position: absolute; right: 3px; top: 3px; background: rgba(0,0,0,.65); color: #fff; font-size: 0.68rem; padding: 0 4px; border-radius: 4px; text-decoration: none; }
.pic.low { border-color: var(--err); }
.cand.low { box-shadow: inset 0 0 0 2px var(--err); }
.badge.low { background: #b91c1c !important; }
.editbox textarea { min-height: 70px; }
.review-head { position: sticky; top: 53px; z-index: 5; background: var(--bg); padding: 8px 0; }

video { width: 100%; max-height: 70vh; border-radius: 8px; background: #000; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login form { display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .grid.two { grid-template-columns: 1fr; }
  .chunk { grid-template-columns: 28px minmax(0, 1fr); }
  .chunk .pics { grid-column: 2; }
  .chooser { grid-column: 1 / 3; }
  .pic { width: 140px; }
  .review-head { top: 92px; }
}

/* interface language switch */
.langswitch { display: inline-flex; gap: 2px; }
.langswitch button { padding: 2px 7px; font-size: 0.75rem; }
.langswitch button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
