:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5c6470;
  --border: #dfe3e8;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --danger: #dc2626;
  --stage: #0f1115;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaee;
    --muted: #9aa3b0;
    --border: #2a2f38;
    --accent: #5b8def;
    --accent-text: #0b1020;
    --ok: #4ade80;
    --danger: #f87171;
    --stage: #000;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header.top,
main,
footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-top: 24px;
  padding-bottom: 16px;
}

h1 { margin: 0; font-size: 1.5rem; line-height: 1.2; }
h2 { margin: 0 0 12px; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

.step {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.8rem;
}

.status {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--card);
}
.status.ok { color: var(--ok); }
.status.error { color: var(--danger); }

main {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  align-items: start;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  min-width: 0;
}
.card.wide { grid-column: 1 / -1; }

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
}

form { display: grid; gap: 12px; max-width: 520px; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
label small { font-weight: 400; color: var(--muted); }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }

input[type="text"], input:not([type]), input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}
input[type="range"] { width: 140px; accent-color: var(--accent); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 12px 0 0; }
form .controls { margin: 0; }

button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--stage);
  border-radius: 8px;
  overflow: hidden;
}
.stage video,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8b93a1;
}
#placeholder[hidden] { display: none; }

.hint, .empty { color: var(--muted); font-size: 0.85rem; margin: 8px 0 0; }
.message { min-height: 1.5em; margin: 12px 0 0; font-size: 0.9rem; color: var(--muted); }
.message.ok { color: var(--ok); }
.message.error { color: var(--danger); }

.people { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.people li:not(.empty) {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.people .empty { grid-column: 1 / -1; margin: 0; }
.thumbs { display: flex; }
.thumbs img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--card);
  margin-left: -10px;
}
.thumbs img:first-child { margin-left: 0; }
.person-label { display: grid; flex: 1; min-width: 0; }
.person-label strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-label span { color: var(--muted); font-size: 0.8rem; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
table[hidden] { display: none; }

footer { padding-top: 24px; padding-bottom: 32px; color: var(--muted); font-size: 0.85rem; }
footer p { margin: 4px 0; }
footer a { color: inherit; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
