:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #181a1f;
  --panel-2: #20242b;
  --line: #303640;
  --text: #f3f5f7;
  --muted: #9ba5b2;
  --accent: #28c2a0;
  --accent-2: #ffcc5c;
  --danger: #ff6b6b;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
a {
  font: inherit;
}

button,
.download,
.upload-zone {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #041310;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand p,
.upload-zone small,
.status-card p,
.hint-row,
.face-meta {
  color: var(--muted);
}

.upload-zone {
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 148px;
  padding: 22px;
  border: 1px dashed #46505d;
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: center;
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(40, 194, 160, 0.16);
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
}

.panel-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.panel-section.compact {
  gap: 14px;
}

.section-title,
.slider-row,
.time-row,
.hint-row,
.topbar,
.toolbar,
.segmented {
  display: flex;
  align-items: center;
}

.section-title {
  justify-content: space-between;
  gap: 12px;
}

.section-title h2 {
  font-size: 15px;
}

.section-title span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.face-list {
  display: grid;
  gap: 10px;
  min-height: 46px;
}

.face-list.empty {
  place-items: center;
  min-height: 90px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.face-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.face-item img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
}

.face-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.face-meta {
  margin-top: 2px;
  font-size: 12px;
}

.remove-face {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.slider-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 34px;
  gap: 10px;
  font-size: 13px;
}

.slider-row b {
  color: var(--accent-2);
  text-align: right;
}

input[type="range"] {
  accent-color: var(--accent);
}

.status-card {
  margin-top: auto;
}

.state-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.state-dot::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-2);
}

.state-dot.ready::before {
  background: var(--accent);
}

.state-dot.warn::before {
  background: var(--danger);
}

progress {
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #111419;
}

progress::-webkit-progress-bar {
  background: #111419;
}

progress::-webkit-progress-value {
  background: var(--accent);
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto auto auto;
  gap: 16px;
  min-width: 0;
  padding: 20px;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.segmented button,
.toolbar button,
.download,
.icon-btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text);
}

.segmented button {
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.toolbar {
  gap: 8px;
}

.toolbar button,
.icon-btn,
.download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: var(--panel-2);
  border-color: var(--line);
  text-decoration: none;
}

.toolbar .download {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #171103;
  font-weight: 900;
}

.toolbar button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #041310;
  font-weight: 900;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.stage-wrap {
  display: grid;
  min-height: 0;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #060708;
  box-shadow: var(--shadow);
}

video,
canvas {
  grid-area: 1 / 1;
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 190px);
  width: auto;
  height: auto;
}

#overlay {
  position: relative;
  z-index: 2;
}

#renderCanvas {
  display: none;
  position: relative;
  z-index: 3;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 22px;
}

.timeline-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.time-row {
  gap: 12px;
}

.time-row span {
  width: 74px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.time-row input {
  flex: 1;
}

.icon-btn {
  width: 42px;
  padding: 0;
}

.hint-row {
  justify-content: space-between;
  min-height: 38px;
  gap: 12px;
  font-size: 13px;
}

.download.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.face-board,
.compare-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.face-board {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.board-header,
.drop-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.board-header h2 {
  font-size: 15px;
}

.board-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.board-header span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.drop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.drop-zone {
  display: grid;
  gap: 10px;
  min-height: 128px;
  padding: 12px;
  border: 1px dashed #48525f;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(40, 194, 160, 0.08);
}

.drop-title strong {
  font-size: 14px;
}

.drop-title span {
  color: var(--muted);
  font-size: 12px;
}

.candidate-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 8px;
  min-height: 62px;
}

.empty-drop {
  display: grid;
  place-items: center;
  min-height: 62px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.candidate-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: grab;
}

.candidate-card:active {
  cursor: grabbing;
}

.candidate-card img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
}

.candidate-card strong,
.candidate-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-card strong {
  font-size: 13px;
}

.candidate-card span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.compare-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  overflow: hidden;
}

.compare-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 160px;
  background: #070809;
}

.compare-cell span {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.compare-cell canvas {
  max-width: 100%;
  max-height: 260px;
}

.stage.manual #overlay {
  cursor: crosshair;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented,
  .toolbar button {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .stage {
    min-height: 320px;
  }

  .time-row {
    display: grid;
    grid-template-columns: 42px 70px 1fr 70px;
  }

  .drop-grid,
  .compare-panel {
    grid-template-columns: 1fr;
  }
}
